A simple accelerometer
You tape one end of a piece of string to the ceiling light of your car and hang a key with mass m to the other end (Figure 5.7). A protractor taped to the light allows you to measure the angle the string makes with the vertical. Your friend drives the car while you make measurements. When the car has a constant acceleration with magnitude a toward the right, the string hangs at rest (relative to the car), making an angle $B$ with the vertical.
(a) Derive an expression for the acceleration $a$ in terms of the mass m and the measured angle $B$.
(b) In particular, what is a when $B$ = 45? When $B$ = 0?
I don't care about the answers, the important thing is the following:-
The book says The string and the key are at rest with respect to the car, but car, string, and key are all accelerating in the +x direction. Thus, there must be a horizontal component of force acting on the key.
That's the reason the book decided to consider a force in the $+x$ direction, but I'm looking for a better explanation: how would I find detect the force in the $+x$ direction in another way? To me, when I draw the free body diagram of the string, there looks to be no force acting on the $+x$ direction! I understand it starts with noticing that the string is attached to the ceiling of the car, and that the car has force causing acceleration in one direction, but I don't know how to go further than that.