9.9 Keyboard object
Description
You can query/set key states with the Keyboard object. The mouse buttons (left, middle, right) will be queried with this object, too. (You can use the
mouse button constants for this)
List of methods/properties
Name | Type | Short description |
GetKeyState | Method | Queries the state of a key |
GetKey | Method | Returns the key code of the last pressed key |
GetKeyText | Method | Returns the key code of the last pressed key considering to the char repeat |
SetKeyState | Method | Sets the state of a key |
Description
With this method you can query the current key state of a specified key. You can use the
virtual key code constants for this. This method returns a value unequal to zero if the key is pressed. This method is equivalent to the Windows function GetAsyncKeyState.
Syntax
1
Keyboard.GetKeyState(Keycode)
Return value
Word
Type
Method
Parameter: Keycode
Description
Datentyp
Dword
Example
1
2
$
v[1] = Keyboard.GetKeyState(VK_DOWN)
If the key [Arrow down] is pressed then v[1] whould be at end -32767 or -32768, otherwise 0 or 1.
Description
Queries all keys from 1 to 254 and returns the first number of the pressed key. If no key is pressed this method will return 0.
Syntax
Return value
Dword
Type
Method
Example
1
2
$
v[1] = Keyboard.GetKey()
At the end the virtual key code of the last pressed key whould be returned. But only the first found key will be returned. If more than one key is pressed at the same time then only the lower virtual key code will be returned. Hence you should use the
GetKeyText method for text input.
Description
Queries all keys from 1 to 254 and returns the first number of the pressed key considering to the char repeat. If no key is pressed with expedient char repeat this method will return 0. This method can be used for text input.
Syntax
Return value
Dword
Type
Method
Example
1
2
$
v[1] = Keyboard.GetKeyText()
At the end the last pressed key (considering to the char repeat) whould be returned. If you use this in a loop then you could input chars in the correct order. If a char whould be hold down then the char repeat whould make sure that not each loop will return this key code.
Description
You can set the state of a key with this method. You can use the
virtual key code constants for this. To specify the key state you can use the
key state constants. This method is equivalent to the windows function keybd_event.
Syntax
1
Keyboard.SetKeyState(Keycode, Keystate)
Return value
None
Type
Method
Parameter: Keycode
Description
Datentyp
Dword
Parameter: Keystate
Description
Datentyp
Dword
Example
1
2
$
Keyboard.SetKeyState(VK_RIGHT, KEYEVENTF_KEYDOWN)
At the end the player whould try to move right, because the computer thinks the right arrow key is pressed. This will stop if the right arrow key is released (in this case you must even press it first!). To "release" the key via DestinyScript you can use the KEYEVENTF_KEYUP constant instead of KEYEVENTF_KEYDOWN.