?
Solved

What key have I pressed?

Posted on 1998-10-13
14
Medium Priority
?
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +4
14 Comments
 
LVL 9

Expert Comment

by:david_levine
ID: 1725227
What language are you developing in?
0
 
LVL 14

Expert Comment

by:smeebud
ID: 1725228
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
ID: 1725229
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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 14

Expert Comment

by:smeebud
ID: 1725230
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
ID: 1725231
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
ID: 1725232
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
ID: 1725233
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
 
LVL 2

Expert Comment

by:Laphroaig
ID: 1725234
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
ID: 1725235
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
ID: 1725236
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
ID: 1725237
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
ID: 1725238
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
ID: 1725239
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 200 total points
ID: 1725240
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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

752 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