Solved

GetKeyNameText without keyboard input but with saved datas

Posted on 2006-07-12
6
710 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

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

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.
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.
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

626 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