Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Thread Tools Display Modes
Old 01-06-2001, 12:12 AM
Goober Goober is offline
Junior Member
Join Date: Jan 2001
Posts: 17
Default Too stupid to work out how to use GetKeyboardState

I found this information, but I'm too thick to work out what it means. Could someone please tell me in laymens terms how to use it?

Thanks an awful lot, this is really doing my head in.
The GetKeyboardState function copies the status of the 256 virtual keys to the specified buffer.

BOOL GetKeyboardState( PBYTE lpKeyState
// address of array to receive status data


Points to the 256-byte array that will receive the status data for each virtual key.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

An application can call this function to retrieve the current status of all the virtual keys. The status changes as a thread removes keyboard messages from its message queue. The status does not change as keyboard messages are posted to the message queue.

When the function returns, each member of the array pointed to by the lpKeyState parameter contains status data for a virtual key. If the high-order bit is 1, the key is down; otherwise, it is up. If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key’s indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.

To retrieve status information for an individual key, use the GetKeyState function.

An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL and VK_MENU as indices into the array pointed to by lpKeyState. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as indices to distinguish between the left and right instances of those keys: VK_LSHIFT



These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
Reply With Quote
Old 01-06-2001, 09:32 PM
douglas douglas is offline
Senior Member
Join Date: Jul 2001
Posts: 7,695
Default RE: Too stupid to work out how to use GetKeyboardState

GetKeyboardState just gets the information of the input devices.

For example:

KS: TKeyboardstate;

//0=OFF 1=ON

This gets the keyboard state, then sets the CAPS ON and then sets it to Windows again.

Of course if you already have CAPS LOCK on, then nothing will change.

Hope that helps.
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

All times are GMT. The time now is 03:15 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.