Consultor Eletrônico



Kbase 21380: How To Call WIN32 API Function: keybd_event
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/15/2008
Status: Verified

GOAL:

How To Call WIN32 API Function: keybd_event

FIX:

By using calls to the Windows keybd_event API function, a Progress 4GL application can perform tasks as though the user had clicked on the Start menu button, or pressed the Caps Lock key, etcetera. (For a complete listing of the many events this API function can perform, do a Web search using the string "Virtual-Key Codes" and/or "keybd_event".)

This example demonstrates how to activate the Caps Lock using the keybd_event API function.  The code was tested on a Windows NT 4.0 Workstation only.  In this example we use the virtual key value of 20 that corresponds to the Caps Lock key.


/************************************************/
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.

PROCEDURE keybd_event EXTERNAL "USER32.DLL":
   DEFINE INPUT  PARAMETER bVk         AS SHORT NO-UNDO.
   DEFINE INPUT  PARAMETER bScan       AS SHORT NO-UNDO.
   DEFINE INPUT  PARAMETER dwFlags     AS LONG NO-UNDO.
   DEFINE INPUT PARAMETER dwExtraInfo AS LONG NO-UNDO.
   DEFINE RETURN PARAMETER intResult  AS LONG NO-UNDO.
END PROCEDURE.

RUN keybd_event (20, 0, 0, 0, OUTPUT intResult).

IF intResult = 1 THEN
   MESSAGE "Caps Lock is ON" VIEW-AS ALERT-BOX.
ELSE
   MESSAGE "Caps Lock is OFF" VIEW-AS ALERT-BOX.
/************************************************/