Solved

GetKeyNameText without keyboard input but with saved datas

Posted on 2006-07-12
6
675 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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 50 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Shell script to login to remote m/c and execute commands 10 72
countEvens challenge 2 57
noX challenge 17 76
wordmultiple challenge 12 89
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

12 Experts available now in Live!

Get 1:1 Help Now