Wednesday, July 01, 2015
    Search Web Link
Search Software
API Home » Keyboard » GetKeyState


Category: Keyboard
Hits: 16707 Rating: GetKeyState has been rated 2.95 by  1562 users (2.95) votes 1562
Rate: 1-star  2-stars  3-stars  4-stars  5-stars
E-mail this API to friend E-mail this Code to a friend  save Bookmark this VB API Function
API Explanation
GetKeyState returns the current status of one of the keys on the keyboard. This status contains two pieces of information: the key's toggle state and the key's pressed state. The information is put into the return value. The toggle state is analogous to the toggle nature of the Caps Lock, Num Lock, and Scroll Lock keys, but Windows records toggle information about every key. The toggle information is stored in bit &H80 of the return value. The pressed state is true if the key is currently being depressed. The pressed information is stored in bit &H01 of the return value. See the example for more information on how to use the return value.

Parameter Information
Declare Function GetKeyState Lib "user32.dll" (ByVal nVirtKey As Long) As Integer

The virtual key code of the key to read the status of.

' Read and display the status of the Enter key
' Enter's virtual key code = 13
Dim keystate As Long ' receives key state

keystate = GetKeyState(13) ' read the Enter key's status
' Display its pressed and toggle status
If (keystate And &H01) = &H01 Then Debug.Print "Enter key is being pressed."
If (keystate And &H80) = &H80 Then Debug.Print "Enter key is toggled."

Copyright © 2000 - 2013 Ex-designz. All rights reserved. Website Developed By Dexter Zafra of
Link to us | Advertisement | Contact us | Privacy Policy | Terms of use | Accessibility