Solved

GetKeyNameText without keyboard input but with saved datas

Posted on 2006-07-12
6
706 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
[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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 159
zeroMAx challenge 20 135
I could not set window to top 4 62
Example code 13 42
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Suggested Courses

739 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