Results 1 to 7 of 7

Thread: Distinguish Keypresses without Direct X

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    105

    Distinguish Keypresses without Direct X

    Is there a way to distinuish between left and right shifts, Ctrls and Alts - without resorting to using Direct X?

  2. #2
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Distinguish Keypresses without Direct X

    You can use the Keyascii asignments that are numbers. You will have to find a list of all the numbers for each key because I don't have one, but here is the code to run the Keyascii.

    VB Code:
    1. Private Sub form_KeyPress(KeyAscii as Integer)
    2.  
    3. If KeyAscii = 'here is where you find the number of the key and enter it
    4.  
    5. End Sub

  3. #3
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Distinguish Keypresses without Direct X

    KeyAscii doesnt support it, paralinx. You have to use the KeyDown/KeyUp events, or use the GetAsyncKeyState API.

    DirectInput is much better because it retrieves input directly from your input devices rather than through Window messages. On top of that, it allows you to press multiple keys at once very easily.

  4. #4
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: Distinguish Keypresses without Direct X

    Hm, well I thought he was trying to tell the difference between the left and right shift keys, the Keydown event only has one vbKeyShift and vbKeyControl.

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Distinguish Keypresses without Direct X

    Actually it does support Alt. It's KeyCode is 18

    And thats the problem with the KeyDown/KeyUp events. Even though theres a left and right control/alt/shift, it's considered as the same KeyCode. DirectInput on the other hand has them as 2 separate keycodes so you can distinguish one from the other. Like I said it's way better.

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Distinguish Keypresses without Direct X

    You can, as already mentioned, use the GetAsyncKeyState function. First use the KeyDown event and check if Shift (for example) is pressed, you can then call GetAsyncKeyState and pass VK_LSHIFT to check if it's the left shift key that has been pressed, if not VB_RSHIFT must have been pressed (this does not work on Win9x).

  7. #7
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Distinguish Keypresses without Direct X

    so anyone please explain how to distinguish them in Win 9x.
    Show Appreciation. Rate Posts.

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