PDA

Click to See Complete Forum and Search --> : Keycode values


Alpine
Nov 20th, 1999, 01:03 PM
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

ShadowCrawler
Nov 21st, 1999, 04:56 AM
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: craigkovatch@compuserve.com
ICQ#: 9872708 (http://wwp.mirabilis.com/9872708)

SteveS
Nov 21st, 1999, 07:39 AM
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.

Alpine
Nov 21st, 1999, 12:26 PM
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

Alpine
Nov 22nd, 1999, 12:11 AM
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