Results 1 to 5 of 5

Thread: How do I get keyboard scancodes and know it's an extended key?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    25

    How do I get keyboard scancodes and know it's an extended key?

    How or with what API can I know which key is an extended key to be able to use keybd_event with the correct dwFlags?

    If I only know how to make a listing like JackTripper did on following link, then I would know that every key starting with a scancode of E0 arebe extended keys.
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms646304.aspx
    ...
    N 31
    M 32
    < , 33
    > . 34
    ? / 35
    R SHIFT 36
    L CTRL 1D
    L ALT 38
    Space Bar 39
    R ALT E0 38
    R CTRL E0 1D
    Insert E0 52
    Delete E0 53
    L Arrow E0 4B
    Home E0 47
    End E0 4F
    Up Arrow E0 48
    Dn Arrow E0 50
    Page Up E0 49
    ...
    Last edited by onidarbe; Jul 2nd, 2013 at 09:16 AM.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How do I get keyboard scancodes and know it's an extended key?

    See the MapVirtualKey function.

    Quote Originally Posted by MSDN
    Translates (maps) a virtual-key code into a scan code or character value, or translates a scan code into a virtual-key code.
    Code:
    Private Enum MapVKTypeConstants
        MAPVK_VK_TO_VSC = 0
        MAPVK_VSC_TO_VK = 1
        MAPVK_VK_TO_CHAR = 2
        MAPVK_VSC_TO_VK_EX = 3
    End Enum
    #If False Then
        Dim MAPVK_VK_TO_VSC, MAPVK_VSC_TO_VK, MAPVK_VK_TO_CHAR, MAPVK_VSC_TO_VK_EX
    #End If
    
    Private Declare Function MapVirtualKeyW Lib "user32.dll" (ByVal uCode As Long, ByVal uMapType As MapVKTypeConstants) As Long

    EDIT


    From the WM_KEYDOWN/WM_KEYUP messages:

    Quote Originally Posted by MSDN
    For enhanced 101- and 102-key keyboards, extended keys are the right ALT and CTRL keys on the main section of the keyboard; the INS, DEL, HOME, END, PAGE UP, PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; and the divide (/) and ENTER keys in the numeric keypad. Other keyboards may support the extended-key bit in the lParam parameter.
    EDIT 2

    Also from the Keystroke Message Flags:

    Quote Originally Posted by MSDN
    Extended-Key Flag

    The extended-key flag indicates whether the keystroke message originated from one of the additional keys on the enhanced keyboard. The extended keys consist of the ALT and CTRL keys on the right-hand side of the keyboard; the INS, DEL, HOME, END, PAGE UP, PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; the NUM LOCK key; the BREAK (CTRL+PAUSE) key; the PRINT SCRN key; and the divide (/) and ENTER keys in the numeric keypad. The extended-key flag is set if the key is an extended key.
    Last edited by Bonnie West; Jul 2nd, 2013 at 01:18 PM. Reason: Added API declaration
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    25

    Re: How do I get keyboard scancodes and know it's an extended key?

    So rather then a api telling if a key is an extended key, I need to make a list of them, because there are always the same no matter what keyboard, right?

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How do I get keyboard scancodes and know it's an extended key?

    Well, checking if a key belongs to the extended key list would seem to be the easiest way. However, MSDN mentions that "Other keyboards may support the extended-key bit in the lParam parameter." so, that method isn't very reliable. I haven't been able to find the proper solution yet, but in the meantime, that method should suffice for most purposes. Sorry!
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    25

    Re: How do I get keyboard scancodes and know it's an extended key?

    ok, thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width