<< Click to Display Table of Contents >> Navigation: Reference (Scripting) > Docklight Script Commands - The DL Object > Methods (Advanced) > GetKeyState |
Returns the state of a specific keyboard key, mouse button or similar input.
Syntax
result = DL.GetKeyState( virtKey )
The GetKeyState method syntax has these parts:
Part |
Description |
virtKey |
Required integer value. An ASCII or virtual key code. If they requested key is a digit from 0-9, or a letter from A-Z, the corresponding ASCII code is used. For other keys and buttons, see the Virtual-Key Codes table available in the Microsoft Windows Docs. |
Remarks
The GetKeyState argument and return value correspond to the Windows GetKeyState function from the Winuser.h library.
For virtual keys (e.g. F1-F12, multimedia keys, mouse buttons a.s.o), you can use the VBScript declarations in the GetKeyState_ImportFile_VirtualKeys.pts file from the ScriptSamples\Extras\GetKeyState_Example folder. We recommend copying the file to your own script folder and include it using the #include directive.
Example
' Example GetKeyState
' Two virtual key declarations, taken from GetKeyState_ImportFile_VirtualKeys.pts
Const VK_F2 = &h71
Const VK_LBUTTON= &h01
Do
DL.AddComment "Example for F2 function key: DL.GetKeyState(VK_F2)=" & DL.GetKeyState(VK_F2)
If keyDown(Asc("D")) Then
DL.AddComment "D key is pressed"
End If
If keyDown(VK_F2) Then
DL.AddComment "F2 key is pressed"
End If
If keyDown(VK_LBUTTON) Then
DL.AddComment "Left mouse button is pressed"
End If
DL.Pause 500
Loop
Function keyDown(virtKey)
keyDown = (DL.GetKeyState(virtKey) And 128) > 0
End Function
Example Communication Window output:
Example for F2 function key: DL.GetKeyState(VK_F2)=1
Example for F2 function key: DL.GetKeyState(VK_F2)=1
Example for F2 function key: DL.GetKeyState(VK_F2)=1
Left mouse button is pressed
Example for F2 function key: DL.GetKeyState(VK_F2)=1
Left mouse button is pressed
Example for F2 function key: DL.GetKeyState(VK_F2)=1
D key is pressed
Example for F2 function key: DL.GetKeyState(VK_F2)=1
Example for F2 function key: DL.GetKeyState(VK_F2)=-128
F2 key is pressed
Example for F2 function key: DL.GetKeyState(VK_F2)=0
Example for F2 function key: DL.GetKeyState(VK_F2)=0
Example for F2 function key: DL.GetKeyState(VK_F2)=0