A method for controlling a device, comprising: determining 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 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 an angle between the keyboard and the screen of the terminal device according to the first position and the second position; and adjusting 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 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 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 an angle between the keyboard and the screen of the terminal device according to the first position and the second position; and adjusting 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.