Thread: GetAsyncKeyState is case insensitive?

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    12

    GetAsyncKeyState is case insensitive?

    Good morning, I'm a new member of the forum. I' trying from yesterday to use GetAsyncKeyState to create a program that uses the keyboard to be controlled. But I would like to understand why if I use like a argument of the function "A" or "a", i have the same result, so I tried to save into a file the keys that i pressed, and i found that the result was always, "A". And now i don't know how to do.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I don't know about you, but I've only got one 'a' key on my keyboard. I don't have a separate key for 'A' and for 'a'. However, you can also tell whether the shift-key (or alt, or control, or whatever) is also being pushed.

    EDIT: As always, the source: http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    16
    getasynckeystate is not case sensitive it will always give you A but it can tell you if the shift key was pressed or not

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    So what i can do? I understand that i have one button for each letter but i thought that normally the function got lowercases letters.
    If i push any button i got an uppercase letter and i want lowercase letter and uppercase only with Caps active or shift held.
    There is some way to solve this problem?

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Put on your thinking cap and talk it out. Put in words what you want, then turn it in to code. Something like:
    • If the key 'A' was pressed, and the shift key AND caps lock were OFF, then I really have an 'a'.
    • If the 'A' key was pressed, and the shift key AND caps lock were ON, then I really have an ___ (remember: shift + caps cancel out for letters).
    • If the 'A' key was pressed, and the shift key was ON, and caps lock was OFF, then I really have an ___.
    • If the 'A' key was pressed, and the shift key was ON, and caps lock was OFF, then I really have an ___.


    Can you fill in those blanks? That's the verbose way to do it. You can combine some of those if statements to simplify it a bit, but I'll leave that up to you.

  6. #6
    Registered User
    Join Date
    Jul 2011
    Posts
    16
    Quote Originally Posted by anduril462 View Post
    Put on your thinking cap and talk it out. Put in words what you want, then turn it in to code. Something like:
    • If the key 'A' was pressed, and the shift key AND caps lock were OFF, then I really have an 'a'.
    • If the 'A' key was pressed, and the shift key AND caps lock were ON, then I really have an ___ (remember: shift + caps cancel out for letters).
    • If the 'A' key was pressed, and the shift key was ON, and caps lock was OFF, then I really have an ___.
    • If the 'A' key was pressed, and the shift key was ON, and caps lock was OFF, then I really have an ___.


    Can you fill in those blanks? That's the verbose way to do it. You can combine some of those if statements to simplify it a bit, but I'll leave that up to you.
    Good suggestion but i dont think it would work coz i hav already tried somthing like that but i will try it.

  7. #7
    Registered User
    Join Date
    Jul 2011
    Posts
    16
    @nicauron

    actually if you are working on game or anything like that then its good but if you are working for anything like transfering your key strokes to a file then leave it and try keyboard hooks.

  8. #8
    Registered User
    Join Date
    Jul 2011
    Posts
    12
    I think that it's a good suggestion but it's also difficult. I will try. I'm working to a menu, in which you must choose, and the choise must be copied in a log file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting a string, case insensitive
    By kasprzap in forum C Programming
    Replies: 1
    Last Post: 01-14-2010, 05:04 PM
  2. Case-insensitive hash
    By mets501 in forum C Programming
    Replies: 2
    Last Post: 10-27-2009, 01:50 AM
  3. Case-insensitive getopt()
    By Ehtyar in forum C Programming
    Replies: 10
    Last Post: 11-20-2008, 03:21 AM
  4. Making a CString map case insensitive
    By tygernoot in forum C++ Programming
    Replies: 4
    Last Post: 06-20-2005, 01:01 PM
  5. case insensitive strstr?
    By Mox in forum C Programming
    Replies: 2
    Last Post: 03-06-2002, 03:11 PM