Solved

What key have I pressed?

Posted on 1998-10-13
14
193 Views
Last Modified: 2013-12-29
Does anybody know how to get windows to give you a string containing the name of the key you have just pressed?
I have found a function called GetKeyNameText, which almost does what I need, the only problem is that windows refers to the cursors as PAD 4, etc.  Is there any way of getting the correct key name?
0
Comment
Question by:wuk
  • 4
  • 3
  • 2
  • +4
14 Comments
 
LVL 9

Expert Comment

by:david_levine
Comment Utility
What language are you developing in?
0
 
LVL 14

Expert Comment

by:smeebud
Comment Utility
Get Regmon and see if that nails it down for you
http://www.sysinternals.com/regmon95.zip

Regards, Bud
http://www.geocities.com/~budallen/
0
 
LVL 9

Expert Comment

by:david_levine
Comment Utility
Smeebud: Regmon? Regmon is for monitoring the registry. I think he's looking for an API call to determine what key has been pressed. Unless I'm misunderstanding the question.
0
 
LVL 14

Expert Comment

by:smeebud
Comment Utility
David,
I only know that programmers do use regmon for seeing
exact parameters???

Regards, Bud
http://www.geocities.com/~budallen/
0
 

Author Comment

by:wuk
Comment Utility
Hey guys, thanks for the response - here is some more info to clear things up a little.  I'm writing a config program for a game using c++, and for the keyboard configuration section, I need to wait for a key and then say 'well done, you just pressed the LEFT key' (for example).  The problem I have is that on different language keyboards, some keys have different names and are in different positions, so I need windows to tell me the real name of the key that has just been pressed in any language and on any keyboard.
Any clues?
Like I said before, the function GetKeyNameText almost does what I need, but it gives the cursor keys the same name as the keypad keys.


0
 
LVL 1

Expert Comment

by:dtavassoli
Comment Utility
Not really an answer, but if thats all the problems you have, just add a
Select Case Result
        Case "PAD1" Result = "END"        
        Case "PAD2" Result = "DOWN"        
        Case "PAD3" Result = "PG DOWN"        
        Case "PAD4" Result = "LEFT"        
       ...
End Select

(Of course, adapt to your language ! I thinks I've been VBing too long)
       
0
 
LVL 2

Expert Comment

by:Laphroaig
Comment Utility
Hello Wuk,

Assuming that you only want to use a small number of keys to control input for your program, then you can program keys individually to produce a user defined ASCII code for each one. As an example you can compile a C++ program and run the resulting *.exe file that will make all 101 keys on your board produce ASCII 65 which is the letter 'A'. Not much use but interesting. You can use the same function to read the existing ASCII code output from each key prior to making any changes. If you save these values in an array, then you can restore them prior to your code completing execution.

Use function set_key(x,y) where x=key number which basically runs top left (esc) to bottom right 'del'. If a large key uses two rows, then it's number coincides with the first row that it is found on. Use void set_key(x,y) where if y>0 then the key 'x' will return ASCII value 'y'. To get the current setting, don't use void, make 'y'=0 and 'y' will return the current setting.
You need to use header file coniob.h to make this function work, ie. #include coniob.h.

Cheers,

Laphroaig.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:Laphroaig
Comment Utility
Sorry!

Forgot to add that if you don't have header file coniob.h then I can email it to you if you give an address. It's got loads of other useful functions included aswell, which I could list and send.

Have fun Mate,

Laphroaig
0
 

Author Comment

by:wuk
Comment Utility
Sorry mate, but I need to have windows tell me the name of the key, it could have been "Print Screen" in spanish, on a French
keyboard!
0
 
LVL 2

Expert Comment

by:Laphroaig
Comment Utility
I was trying to be friendly and helpful, so your flippancy is not really appreciated.

It appears that you don't really know what you you are trying to achieve, yourself,  so you are going to have a hard time trying to make other people understand and help you. If you know how to program in C++ then you would realise that the info I gave you, would allow you to create a windows application that would capture keyboard events and utilise them for your own needs.

Why don't you withdraw the question and re-evaluate your requirements.
0
 
LVL 2

Expert Comment

by:Billy_Pilgrim
Comment Utility
I don't know if this is exactly what you are looking for, but you can use virtual key codes instead.  

Put the following in your message handling loop. You can get all of the virtual key codes in WinUser.H

I'm pretty sure the basic ones here are keyboard-independent but I'm not positive.

case WM_KEYDOWN:
         switch(LOWORD (wParam))
         {
            case VK_LEFT:
               break ;
            case VK_RIGHT:
          }

etc. , etc. . .
0
 

Author Comment

by:wuk
Comment Utility
Laphroaig:
Hey, there is no need to be nasty - I was mearly trying to point out that that kind of situation could, and probably would occur.
As I said in my original message, I need Windows to give me a STRING containing the actual localised name of the key that was just pressed.  For example, if someone presses the SCROLL LOCK key, then I need to know what that key is actually called in whatever language the user is opperating in.  In German it could be something like "SCROLLEN LÖCHEN"!
Sorry if my previous message appeared anything other than friendly.
0
 

Author Comment

by:wuk
Comment Utility
Laphroaig:
Hey, there is no need to be nasty - I was mearly trying to point out that that kind of situation could, and probably would occur.
As I said in my original message, I need Windows to give me a STRING containing the actual localised name of the key that was just pressed.  For example, if someone presses the SCROLL LOCK key, then I need to know what that key is actually called in whatever language the user is opperating in.  In German it could be something like "SCROLLEN LÖCHEN"!
Sorry if my previous message appeared anything other than friendly.
0
 

Accepted Solution

by:
kolev earned 100 total points
Comment Utility
There is NO API function that returns a NAME (description) of a key. At least under 95 and I strongly believe it is same under NT.

I would count this for an answer since it tends to be clear enough.

So the next is free: the most you could do is to get the current layout language and attempt to produce at least the same symbol in your message. For the special keys, though, You'll have to use your names. I think you would not risk much by simply calling them with their original ENGLISH names. Trust me, it will work even better in some cases ;-)

P.S. If anyone prove me wrong [s]he'll have your 100 pts + 50 of mine's.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now