Virtual-Key Codes for special characters - c++

I am trying to get the Virtual-Key Code for another characters out of regular virtual-key codes list, like '<', but I cant find it, it's an ASCII character and I can't find it.

“ASCII” is a character encoding.1 This has very little to do with key codes. For example, “A” and “a” have distinct ASCII values but they are represented by the same key on the keyboard (plus a modifier key — shift).
That’s the reason why you don’t find < in the list — it’s not a key on the (virtual) keyboard represented by these key codes. It depends on the currently active keyboard mapping how this character is represented by by a keycode.
1 And, I might add, not a very relevant one in this day and age. Better forget about ASCII, it’s mostly misused.

Thanks to Hans Passant
VkKeyScanEx() might help.
For example, the Virtual-Key Code equivalent to '<' can be found with:
VkKeyScanEx('<', GetKeyboardLayout(0))

Related

C++ vkCode/ScanCode to country-specific and case-sensitive character

I searched in a lot of different places and didn't find any conclusive answer, so I'm asking here.
I have to make a basic Windows keylogger as a school project.
I managed to set it up, and it works quite well. It logs characters and dead keys.
My problem is handling case-sensitive and country-specific input. I can get the SHIFT key state just fine to convert keys into their upper/lowercase equivalent, but I can't actually know what upper/lowercase equivalent it corresponds to.
Example : I'm using a French AZERTY keyboard. Numbers can be written via SHIFT + &, SHIFT + é, etc.
Here are the results my keylogger displays when trying to log numbers 1 to 5, first via SHIFT + Number and then by using CAPS LOCK.
If I switch to an English QWERTY keyboard, it will probably work fine, displaying the numbers (but then I'll not be able to access other characters like parentheses).
Is there any way to get a list of all possible keys for a given ScanCode/vkCode, depending on the type of keyboard ?
Here's a part of my code for the Callback function, and the translation of keys to strings.
It's the first time I use Windows' C++ API, so I don't really know much about it.

hyphen character and apostrophe character - the same ASCII code in different languages?

I need to specify a regex for validation of user input that allows the user to enter a hyphen character or apostrophe character on Windows Desktop operating systems or Mac OS/X desktop operating systems.
The user may have configured for the following languages:
English
French
Spanish
Portuguese
Hawaiian
I wan't to understand if I use a standard ASCII regex for hyphen and apostophe (e.g. ['-]) whether that will catch the hyphen or apostrophe keys typed by the user in most cases. I appreciate my definition is quite loose as there are many different keyboard layouts, OS versions, and language definitions (e.g. fr_FR, ca_FR).
I have checked the following resources and generally searched on google, but could not find anything in particular about saying that the ASCII code generated by a hyphen key or apostrophe key will always be ASCII code 45 and ASCII code 39 respectively.
http://en.wikipedia.org/wiki/Keyboard_layout
http://en.wikipedia.org/wiki/Hyphen
http://en.wikipedia.org/wiki/Apostrophe
NOTE: If you feel this question is badly worded, please add a comment to help me improve it.
You're mixing up a couple of things:
keyboard layout is what determines what value get assigned to a scancode.
localization settings determine in what language you should address the user, and wether the user expects a decimal point or comma.
character encoding is how a glyph is encoded into the bits memory and, in reverse, how to decode bits into glyphs
If you're validating user input, you shouldn't be interested in scancodes. A DVORAK layout user on a QWERTY keyboard will be pressing the Q key to input an '. And you shouldn't mess with that. So you have no business dealing with keyboard layouts.
The existence of this keyboard, should remind you, that what keys do is not your head-ache, but up to the user.
The localization settings will matter to you, but not for your regex. They will, however, tell you in what language you should put your error message, in case the user input is invalid. A good coding practice is to use a library like gettext to manage this.
What matters most, when you are validating input. Is just those 2 things: what is valid and what is the input.
You (or your domain expert) decide what is valid. Wether a hyphen-minus is just as acceptable as a hyphen or n-dash.
The input will be in encoded; computers work with bits, not strings of glyphs. It could be ASCII, but I'd steer towards unicode if I could help it.
As for your real concern, if I may rephrase it: "Can all users easily enter ' and -?". I guess they probably can. Many important programming languages use those glyphs to resp. denote strings and as a subtraction operator. And if your application needs to (dis)allow certain glyphs you can put unicode code points or categories in your regex.

How to use wm_deadchar to send non Ascii signs

i'm trying to send an umlaut keyevent with the function keybd_event. The Windows Documentation states that: "A dead key is a key that generates a character, such as the umlaut (double-dot), that is combined with another character to form a composite character. For example, the umlaut-O character (Ö) is generated by typing the dead key for the umlaut character, and then typing the O key."
How do i emit a dead key?
I tried the following without success:
keybd_event(WM_DEADCHAR,0x0103,0,0);
keybd_event(0x4F,0,0,0);
Sorry for my bad english.
I look forward to your reply.
The first argument to keybd_event is a virtual-key code. E.g. for my keyboard the dead key " is VK_OEM_7.

Converting a VK_CODE into a displayable string

When writing a Windows application, the documentation says that some VK_CODEs are displayable characters, like VK_OEM1 is "o with an umlaut". How can I go from the WPARAM of non-ASCII characters into a displayable string? I'm using UTF-16.
Maybe you're looking for the GetKeyNameText Function
It retrieves a string that represents the name of a key.
like VK_OEM1 is "o with an umlaut".
Maybe on your machine. Not on mine, it is ';' or ':', depending on the Shift key state. These are virtual key codes. The ones that represent a typing key get converted to a character by ToUnicodeEx(), a function that takes a keyboard layout. And of course you have the non-typing keys that produce no character at all, like VK_F1 or VK_NUMLOCK. This gets a lot more complicated when the keyboard layout has dead keys, the kind you use to get a diacritic on top of a character. That why the function also requires a keyboard state.
Avoid this like the plague, WM_CHAR is your friend.

Can all keys be represented as a single char in c++?

I've searched around and I can't seem to find a way to represent arrow keys or the escape key as single char in c++. Is this even possible? I would expect that it would be similar to \t or \n for tab and new line respectively. Whenever I search for escaped characters, there's only ever a list of five or six well known characters.
The short answer is no.
The long answer is that there are a number of control characters in the standard ANSI character set (from decimal 1 to decimal 31, inclusive), among which are the control codes for linefeed, carriage return, end-of-file, and so on. A few are commonly interpreted as arrows and the escape key, but only for compatibility with terminals.
Standard PC keyboards send a 2- or 3-byte control code that represents the key that was pressed, what state it's in, which control/alt/shift key is pressed, and a few other things. You'll want to look up "key codes" to see how to handle them. Handling them differs between operating systems and the base libraries you use, and their meaning differs based on the operating system's configured keyboard layout (which may include characters not found in the ANSI character set).
Not possible; keyboards built for some languages have characters that can't be represented in a char, and anyway, how do you represent control-option-command-shift-F11 in a char?
Keyboards send scancodes, which are either some kind of event in a GUI system or a short string of bytes that represent the key. What codes depends on your system, but on most terminal-like systems, ncurses knows how to deal with them.
char variables usually represent elements in the ASCII table.
http://www.asciitable.com/
there is also man ascii on unix. If you want arrow keys you'll need a more direct way to access keyboard input. the arrow keys get translated into sequences of characters before hitting stdio. If oyu want direct keyboard access consider a GUI library, sdl, direct input to name a few.
There aren't any escape characters for the arrow keys. They are represented as Keycodes, afaik. I suggest using a higher level input library to detect key presses. If you want to do it from scratch, the approach taken might vary with the specific platform you are programming for.
In any case, back in the days of TURBO C, I used -
//Wait for keypress
//store input in ch
//see if the ASCII code matches the code for one of the arrow keys