directinput DIK to VK?

This is a discussion on directinput DIK to VK? within the Game Programming forums, part of the General Programming Boards category; i googled it and came up with a few results, heres what 1 of them suggested: Code: static int scan2ascii(DWORD ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    directinput DIK to VK?

    i googled it and came up with a few results, heres what 1 of them suggested:

    Code:
    static int scan2ascii(DWORD scancode, ushort* result)
    {
       static HKL layout=GetKeyboardLayout(0);
       static uchar State[256];
    
       if (GetKeyboardState(State)==FALSE)
          return 0;
       UINT vk=MapVirtualKeyEx(scancode,1,layout);
       return ToAsciiEx(vk,scancode,State,result,0,layout);
    }
    that works fine for letters/numbers, but not for ctrl/alt/arrow keys/f1-f12/etc.. is there a better way to handle this?

    ive been using GetAsyncKeyState() for keyboard input, but i recently switched to DirectInput and the DIK keys are completely different from the VK keys. if theres no other way, i could just rewrite the input routine to use DIKs instead of VKs.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Just use the DIK constants. It's much easier.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    but the DIK constants are for US keyboards only, what if the user had some other kind of keyboard layout?

  4. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Check the SDK.


    Microsoft DirectX 9.0
    Interpreting Keyboard Data

    --------------------------------------------------------------------------------

    This topic covers the identification of keys for which data is reported by the IDirectInputDevice8::GetDeviceState and IDirectInputDevice8::GetDeviceData methods. For more information about interpreting the data from IDirectInputDevice8::GetDeviceData, see Time Stamps and Sequence Numbers.


    In one important respect, Microsoft® DirectInput® applications read the keyboard differently from the way Microsoft Windows® does. For DirectInput applications, keyboard data refers not to virtual keys but to the actual physical keys—that is, the scan codes. DIK_ENTER, for example, refers only to the ENTER key on the main keyboard, not to the ENTER key on the numerical keypad.

    Additionally, differences among keyboards can affect the way DirectInput applications interpret keyboard data. For example, DirectInput defines a constant for each key on the enhanced keyboard, as well as the additional keys on international keyboards. Because NEC keyboards support different scan codes than the PC-enhanced keyboards, DirectInput translates NEC key-scan codes into PC-enhanced scan codes where possible.

    Other keyboard differences to consider are:


    Not all PC-enhanced keyboards have the Windows logo keys (DIK_LWIN, DIK_RWIN, and DIK_APPS), there is no way to determine whether the keys are physically available.
    Laptops and other small computers often do not implement a full set of keys. Instead, some keys (typically numeric keypad keys) are multiplexed with other keys, which are selected by an auxiliary mode key that does not generate a separate scan code.
    If the keyboard subtype indicates a PC XT or PC AT keyboard, the following keys are not available: DIK_F11, DIK_F12, and all the extended keys (DIK_* values greater than 0x7F). Furthermore, the PC XT keyboard lacks DIK_SYSRQ.
    Japanese keyboards, particularly the NEC PC-98 keyboards, contain a substantially different set of keys than U.S. keyboards. For more information, see DirectInput and Japanese Keyboards.


    --------------------------------------------------------------------------------

    © 2002 Microsoft Corporation. All rights reserved.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectInput and Dev-C++
    By Niara in forum Game Programming
    Replies: 2
    Last Post: 03-11-2005, 09:20 AM
  2. DirectInput woes again....
    By VirtualAce in forum Game Programming
    Replies: 4
    Last Post: 05-25-2004, 03:02 PM
  3. DirectInput key lookup function?
    By Arrow Mk 84 in forum Game Programming
    Replies: 2
    Last Post: 12-10-2002, 04:37 AM
  4. My DirectInput tutorial....
    By jdinger in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-18-2002, 11:32 PM
  5. DirectInput lost with Alt-Tab
    By jdinger in forum Game Programming
    Replies: 2
    Last Post: 05-11-2002, 11:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21