Results 1 to 6 of 6

Thread: Input system

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    29

    Question

    I'm doing an input system to my game with DX8. I use DInput to check if a key has been pressed:

    If data(xi).lOfs And data(xi).lData = bDown Then
    g_TypedLetter = data(xi).lOfs
    End If

    Then my app checks what key was pressed:
    Select Case g_TypedLetter
    Case DIK_A
    newChar = "a"
    Case DIK_B
    newChar = "b"
    Case DIK_C
    newChar = "c"
    Case DIK_D
    newChar = "d"
    etc..

    How can be the conversion from long -> string be optimized?
    And how should be shift+alt keys handled? I can already do uppercase letters with caps lock and both shift buttons, but how to get other symbols (e.g. "(", "{") out of the keyboard?

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I've got an idea... use DInput ONLY for joysticks...

    Use Native VB, it's way easier. I'm not saying that it's the best way to go, though. I've never used DInput, but by your code it looks tough.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    29
    One of the main points in my current project is to avoid using native VB (Form_Keydown and alike) because I want to port it to C++ after I've studied it enough. So are there any API calls that return the ASCII value of a keypress (that also knows how a keyboard is mapped)?

  4. #4
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    You can use GetAsynchKeyState To find out if a particular key has been pressed. It's a Windows API call, so it works in C/C++.
    Harry.

    "From one thing, know ten thousand things."

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    29
    Hmm.. I'd like to use something like GetKeyboardState (which returns a 256-byte array) but it doesn't have keyUp-keyDown-things. How should AsyncKeyState be used that it would also return everything in one package?

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    You don't, you just loop. If you consider how this is working at machine code level, something like GetKeyboardState is going to have to loop through the virtual key codes and assign values to the array it returns. Doing this yourself ought to result in a fairly minimal performance loss, perhaps it would even be quicker if you were only checking some keys (ie. the control keys for your game).

    GetAsynchKeyState will tell you whether the key is down, and also whether it was pressed the last time you checked, so you can tell whether it's been pressed or released, or is just still pressed down since the last time it was pressed.
    Harry.

    "From one thing, know ten thousand things."

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