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

NameTypeShort description
GetKeyStateMethodQueries the state of a key
GetKeyMethodReturns the key code of the last pressed key
GetKeyTextMethodReturns the key code of the last pressed key considering to the char repeat
SetKeyStateMethodSets the state of a key

GetKeyState

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

The number of the key to be queried. You can use the virutal key code constants for this.

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.

GetKey

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

1
Keyboard.GetKey()

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.

GetKeyText

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

1
Keyboard.GetKeyText()

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.

SetKeyState

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

The virtual key code. You can use the virtual key code constants for this.

Datentyp

Dword

Parameter: Keystate

Description

The new key state. You can use the key state constants for this.

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.