Results 1 to 5 of 5

Thread: Keycode values

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    3

    Post

    Hi,

    I'm trying to make a keylogger using the api GetAsyncKeyState in a timer control. I need a way to tell what symbol or character should appear on a keypress. I can make it work for keys like 1,2,a, etc... But not for ones that need shift to be pressed. The way i'm doing this now is by checking the state of the shift key before each key press, but this only works for one keyboard layout.
    Example: Key 3 has the code 51(i think) but I need to get the symbol above key 3. On a UK keyboard this is £, but on a USA keyboard it is #. I need a way to tell what symbol should appear. I know the keycodes or whatever are converted into the correct symbol or character by the driver. Is it possible for me to access the driver or something? Or is there a better way of doing this? It would be a lot easier if I could use the KeyPress event, and get the KeyAscii values, but the program has to work when it doesn't have focus. Is there a way to do it this way?


    Sorry if this makes no sense

    Thanks, Doug

  2. #2
    Member
    Join Date
    Jan 1999
    Location
    Gig Harbor, WA, USA
    Posts
    48

    Post

    There is a huge example in the MSDN Knowledge Base about checking for the shift state. As far as the symbol display, Chr() returns a letter for a keycode, or a keycode for a letter, maybe it can help.

    ------------------
    (¯`·.¸¸.·´¯`·->ShadowCrawler<-·´¯`·.¸¸.·´¯)
    Teenage Programmer
    Visual Basic, HTML, C++, JavaScript

    http://welcome.to/X12Tech
    Email: [email protected]
    ICQ#: 9872708

  3. #3
    Lively Member
    Join Date
    Jun 1999
    Location
    Ireland
    Posts
    96

    Post

    I use the API with the VB consts. and have nop trouble so far even moving to Japanese keyboard layouts.

    Try using something like

    GetAsyncKeyState(vbKeyLeft)

    Most keys have their constants setup in this list, just enter, vbKeyLeft, into your code and press F1 on it. Then you'll get a list of the consts.

    Hope this helps,

    Steve.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    3

    Post

    Hi,

    Thanks for the help guys, it doesn't really solve my problem though. I'm not having any trouble with checking the shift state. Crh() works for keys a-z and 0-9 because the thier ascii values are the same as the keycodes that the api returns. But the ascii value for $, for example, is different. I've used constants where I can, and they work, but I can't find constants for all the symbols, like $ or #. The problem I'm having is that if the 3 key is pressed, the api returns the keycode for the 3 key(51). Then I can use chr(51) or something and this gives me 3. But what I can't get is the symbol above 3. The way I'm doing this now is by checking the shift state.


    Example code:

    If getasynckeystate(51)=-32767 Then
    If Shift then
    Result="£"
    Else
    Result=chr(51)
    Endif
    Endif


    If I run this code(or something like it) on my computer, which has a UK layout keyboard it returns 3 if shift wasn't pressed, or £ if shift was pressed.
    Now, if I run this code on a different keyboard layout(USA for example), it gives me exactly the same result. But on a USA layout keyboard, shift+3 should be #.
    I'm trying to find a way to make it work whatever the keyboard layout is. It works for the keys a-z and 0-9 because the values are the same, and for keys that I can use constant's for, but not the others.
    Any ideas?


    Thanks for the help already provided

    Doug

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    3

    Post

    Hi,

    Thanks for all the help. I've now worked out how to do exactly what I want to to. I can post the code here soon if anyone wants to see it.


    Doug

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