A method for controlling a device, comprising: determining (S101) a distance state between a keyboard and a terminal device, wherein the keyboard is in communication connection with the terminal device; in a case that the distance state is a distant state, adjusting (S102) a state of a screen of the terminal device to a wake-up state, and obtaining a first position of the keyboard and a second position of the terminal device; determining (S103) an angle between the keyboard and the screen of the terminal device according to the first position and the second position; and adjusting (S104) a state of the keyboard according to the angle, characterised in that obtaining the second position of the terminal device comprises: collecting a current position and a current gravity acceleration of the terminal device; determining whether a difference between the current position of the terminal device and a previous position of the terminal device is greater than a distance threshold; and in a case that the difference is greater than the distance threshold, determining whether a difference between the current gravity acceleration of the terminal device and a preset gravity acceleration is greater than an acceleration threshold, and in a case that the difference between the current gravity acceleration and the preset gravity acceleration is greater than the acceleration threshold, taking the current position of the terminal device as the second position. determining (S101) a distance state between a keyboard and a terminal device, wherein the keyboard is in communication connection with the terminal device; in a case that the distance state is a distant state, adjusting (S102) a state of a screen of the terminal device to a wake-up state, and obtaining a first position of the keyboard and a second position of the terminal device; determining (S103) an angle between the keyboard and the screen of the terminal device according to the first position and the second position; and adjusting (S104) a state of the keyboard according to the angle, characterised in that obtaining the second position of the terminal device comprises: collecting a current position and a current gravity acceleration of the terminal device; determining whether a difference between the current position of the terminal device and a previous position of the terminal device is greater than a distance threshold; and in a case that the difference is greater than the distance threshold, determining whether a difference between the current gravity acceleration of the terminal device and a preset gravity acceleration is greater than an acceleration threshold, and in a case that the difference between the current gravity acceleration and the preset gravity acceleration is greater than the acceleration threshold, taking the current position of the terminal device as the second position. collecting a current position and a current gravity acceleration of the terminal device; determining whether a difference between the current position of the terminal device and a previous position of the terminal device is greater than a distance threshold; and in a case that the difference is greater than the distance threshold, determining whether a difference between the current gravity acceleration of the terminal device and a preset gravity acceleration is greater than an acceleration threshold, and in a case that the difference between the current gravity acceleration and the preset gravity acceleration is greater than the acceleration threshold, taking the current position of the terminal device as the second position. <EOS>