MFC: virtualkeys and the "extended" bit

Computer builds, hardware and software discussion or troubleshooting, including peripherals. Essentially a general place to talk about desktop computers.
Locked
Anonymous

MFC: virtualkeys and the "extended" bit

Post by Anonymous »

Hi all,

I'm trying to add keyboard customisation to my app. I need some help understanding the relation between virtual key codes the "extended" bit.

If a user associates numpad 3 with a command, my app will store the value VK_NUMPAD3 (0x63) against that command.
If a user associates page down with a command, my app will store the value VK_NEXT (0x22) against that command.
...
(See http://msdn.microsoft.com/library/d...ualKeyCodes.asp)

So far so good. But when I try to display the string representing the key associated with each command, the VK_xxx value is not sufficient: I also need to know if the key is "extended" or not.
For example, when I use:
CHotKeyCtrl::GetKeyName(UINT virtualkey, bool extended)

I get the following output:
GetKeyName(VK_NUMPAD3, true) //returns PGDOWN
GetKeyName(VK_NUMPAD3, false) //returns NUM 3
GetKeyName(VK_NEXT, true)//returns PGDOWN
GetKeyName(VK_NEXT, false)//returns NUM 3

So here I'd like to use:
. GetKeyName(vkCode, true) if vkCode==VK_NEXT
. GetKeyName(vkCode, false) if vkCode==VK_NUMPAD3
To get the correct string every time, I would need to figure out whether I should to set "extended" for each possible value of vkCode. I don't understand why this is necessary, since the keycodes themselves are sufficient to be distinguished from each other.

To sum up, my questions are:
1. Why is knowledge of the extended bit necessary when calling CHotKeyCtrl::GetKeyName, given that the exact key is already identified by the keycode?
2. Is there a quick way to deduce the correct value of the extended bool based on the virtual key code? Does someone have a map of some sort? (extended = vkCode>0x60 ? false : true works to an extent but still doesn't get strings for all keypresses correct)
3. My understanding is that by using virtual key codes and CHotKeyCtrl::GetKeyName, I am catering for all keyboard layouts. Is this right?

Thanks in advance for any help.

Archived topic from Iceteks, old topic ID:2414, old post ID:20438
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

MFC: virtualkeys and the "extended" bit

Post by Red Squirrel »

I may be wrong but I think an extended key is like the "WWW" key and such on compaq keyboards and other keyboards that have extra buttons.



Archived topic from Iceteks, old topic ID:2414, old post ID:20439
Honk if you love Jesus, text if you want to meet Him!
Anonymous

MFC: virtualkeys and the "extended" bit

Post by Anonymous »

Red Squirrel wrote: I may be wrong but I think an extended key is like the "WWW" key and such on compaq keyboards and other keyboards that have extra buttons.
No I think this is a different kind of "extended", since the extended bit needs to be set to true for the names of common keys like page up to be displayed correctly.

Anyway, I'm now doing this which seems to be working reasonable well, at least on UK and French keyboards:

Code: Select all

...
        myString = CHotKeyCtrl::GetKeyName(code, IsExtended(code));
...

bool CCustEdit::IsExtended(UINT code)
{
        if (code==VK_SNAPSHOT)        //print screen
  return true;
        if (code>=VK_PRIOR && code<=VK_DOWN) //pgup, pg down, home, end,  cursor keys,
  return true;
        if (code>=VK_INSERT && code<=VK_DELETE) // ins, del
  return true;    
        if (code>=VK_LWIN && code<=VK_APPS) //winkeys & application key
  return true;
        if (code==VK_DIVIDE)        //Numpad '/'
  return true;
        if (code==VK_NUMLOCK)        
  return true;

        return false;
}

[code]

I still don't understand the point of this extended bit since the value of the virtual key code implies whether it should be set or not. 

[color=#888888][size=85]Archived topic from Iceteks,  old topic ID:2414, old post ID:20440[/size][/color]
Locked