Consultor Eletrônico



Kbase P41892: How to Call WIN32 API Function: GetKeyState
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   7/13/2005
Status: Unverified

GOAL:

How to Call WIN32 API Function: GetKeyState

GOAL:

How to retrieve the status of the specified virtual key.

GOAL:

How to retrieve the toggle status of CAPS LOCK?

GOAL:

How to retrieve the toggle status of SCROLL LOCK?

GOAL:

How to retrieve the toggle status of NUM LOCK?

FIX:

The following sample code shows how to call the Win32 API function called GetKeyState. This function retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled. You normally use GetKeyState() to check the status of the toggled keys: "CAPS LOCK", "SCROLL LOCK", AND "NUM LOCK".

This code has been tested on Windows NT 4.0 Workstation only.

&GLOBAL-DEFINE VK_SCROLL 145
&GLOBAL-DEFINE VK_NUMLOCK 144
&GLOBAL-DEFINE VK_CAPITAL 20

DEFINE VARIABLE intResult AS INTEGER NO-UNDO.

PROCEDURE GetKeyState EXTERNAL "USER32.DLL":
DEFINE INPUT PARAMETER intVirtKey AS LONG.
DEFINE RETURN PARAMETER intResult AS SHORT.
END PROCEDURE.

RUN GetKeyState (INPUT {&VK_NUMLOCK}, OUTPUT intResult).

IF intResult = 1 THEN
MESSAGE "Key is Toggled 'ON'" VIEW-AS ALERT-BOX.
ELSE
MESSAGE "Key is Toggled 'OFF'" VIEW-AS ALERT-BOX.