Solved

GetKeyNameText without keyboard input but with saved datas

Posted on 2006-07-12
6
701 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Expand data scrubbing tool 13 35
fizzArray  challenge 1 96
tripleUp challenge 7 86
Is there a simple front-end menu system. 9 104
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

830 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