Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

GetKeyNameText without keyboard input but with saved datas

Posted on 2006-07-12
6
Medium Priority
?
714 Views
Last Modified: 2013-11-20
How can I use the GetKeyNameText to display a list of saved keyboard shortcuts ?

Saved datas is (for each keyboard shortcut) :

     VirtualKeyCode
     Alt key pressed or not
     Control key pressed or not
     Short key pressed or not

The problem is that GetKeyNameText gets a scancode in input (scancode is retrieved with MapVirtualKey(VIRTUALKEYCODE, 0)
but not the state of the 3 other keys (Alt, Control or Shift).

For example (AZERTY keyboard) :

 for the "A" key I will always get "A" instead of "A" (shift key is not pressed) or "a" (shift key is pressed)

 for the "&" key I will always get "1" instead of "&" (shift key is not pressed) or "1" (shift key is pressed)
0
Comment
Question by:mike_marquet
  • 5
6 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17089051
>> The problem is that GetKeyNameText gets a scancode in input but not the state of the 3 other keys (Alt, Control or Shift).

Here its how to trap if CTRL / ALT / SHIFT is pressed along with other key...

just perform binary AND with scancode returned with MapVirtualKey with FCONTROL for CTRL key, with FALT for ALT key and FSHIFT for Shift key..

e.g.

int nScanCode = MapVirtualKEy(....);

if(nScanCode & FCONTROL ) // combination of key and CONTROL is pressed

if(nScanCode & FALT) // combination of key and ALT is pressed

if(nScanCode & FSHIFT ) // combination of key and SHIFT is pressed

In this way you can detect if key combination with CTRL/ALT/SHIFT is performed and if you want it in text form you may append appropriate text in text buffer

-MAHESH
0
 

Author Comment

by:mike_marquet
ID: 17089088
The nScanCode returned by MapVirtualKey can not be used with FALT, ...

These masks can only be used for the fVirt member of the structure ACCEL

The scancode is the same if you press the shift key or not.
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17089091
NOTE : FCONTROL , FALT and FSHIFT all are already defined by your common header files just use them.

-MAHESH
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 22

Expert Comment

by:mahesh1402
ID: 17089116
bit mistake ..

change that as follows :

its not scancode returned by MapVirtualKey but its your virtual code only...preform AND with your virtual code directly

e.g if nVirtCode is your virtual code which you pass to MapVirtualKey then

if(nVirtCode & FCONTROL ) // combination of key and CONTROL is pressed

if(nVirtCode & FALT) // combination of key and ALT is pressed

if(nVirtCode & FSHIFT ) // combination of key and SHIFT is pressed

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17089163
try this :

e.g

 CString buf;
 nScanCode = MapVirtualKey(nVirtKey, 0) ;
 nScanCode <<= 16;
 nScanCode++;
 GetKeyNameText(nScanCode,buf,20);

 if( nVirtKey & FCONTROL)
  buf +="+CONTROL";

if( nVirtKey & FALT)
  buf +="+ALT";

if( nVirtKey & FSHIFT)
  buf +="+SHIFT";

MessageBox(buf);

-MAHESH
0
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 200 total points
ID: 17089238
Otherwise Simple solution is to : Use GetKeyStatus() function to retrieve if special keys CTRL,ALT,SHIFT are  DOWN , UP or toggled

look here :http://www.ddj.com/dept/windows/184416874 <=== refer CKeyEdit::ConvertKeyToString() and CKeyEdit::ConvertSpecialKeysToAttrib() functions.

-MAHESH
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

971 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