I am considering creating a custom keyboard layout. The keys are mapped to unicode. One kind of shortcut that I often use is the alt + <arrow> or alt + <backspace>. How can I get the same effect with a unicode?
You can't. Unicode is a standard that describes characters, not keys. There's not even a Unicode code point for the F1 key, let alone for combinations.
The keys are mapped to unicode.
This statement is untrue. Keys are mapped to scancodes. Any mapping to a character set is performed by the OS and not all keys or key combinations necessarily map to a character either. An OS may further abstract key codes into virtual key codes in order to handle the wide variety of keyboard layouts and special keys.
Scancodes are 8-bit values with extended keys producing a code pair - the first being zero (NUL) indicating that a second code follows, thus allowing 510 distinct codes.
Note that the scancode generally applies to the specific key, not the character generated. For "character" keys, shift, alt, ctrl etc. (which have their own distinct scancodes) do not modify the scancode, so "extended" keys such as the functon keys, they can act as modifiers.
Normally you would not access the keyboard at the scancode level, but rather use the OS's keyboard services to determine key states or character mapping. For example by scancode alone you cannot distinguish between N and n - the key state of either left-shift, right-shift, alt-gr and the current caps-lock toggle-state must be considered. Scancode access is primarily for keyboard drivers to deal with.
Higher level keyboard access is OS specific. In Windows for example there is an extensive API and framework for keyboard access. Of interest in this case perhaps are the toUnicode() and toUnicodeEx() functions that map virtual key codes to Unicode (where such a translation exists). However there is no translation for Alt+ AFAIK, In a GUI message loop, you will get a WM_SYSKEYDOWN message with a VK_UP, VK_DOWN, VK_LEFT or VK_RIGHT parameter. In fact you will get other messages, but WM_SYSKEYDOWN is specifically issued for Alt+ sequences so you need not separately process and maintain state for the Alt key WM_KEYDOWN/WM_KEYUP.
Related
When I type a comma in VS code I get
,
but what I really want is
,
I'm not sure why there's two types of commas, but the first one is giving me run time errrors in python
"I'm not sure why there's two types of commas"
Well ... it is because Unicode defines them1. The first one is U+FF0C : FULLWIDTH COMMA. The second one is U+002C : COMMA
The latter is the one that should be bound to the "comma" key on your keyboard, but it is possible that something has changed your VSCode key bindings. This page describes how to examine your VSCode key bindings.
But I think the more likely explanation is that you have copy-pasted some source code from (for example) a PDF file that is using U+FF0C instead of U+002C for cosmetic reasons ... or something. It ia also possible that they were placed there by the author of the original document, or by their word-processing software.
You could try using the Gremlins extension to highlight any potentially troublesome characters in your source code.
1 - According to Wikipedia, the purpose is "so that older encodings containing both halfwidth and fullwidth characters can have lossless translation to/from Unicode.".
I have an English keyboard. With little setting on keyboard preferences on my window machine I am able to type Spanish character.
To type á I have to press two keys.
' + a = á
But when I change to normal English layout I get
' + a = 'a
How is switching between different keyboard/layout gives different result? As per my understandng in both the cases it passes the same keycode but the end results are different.
It should not give the same result, since they are different symbols.
"Spanish" accent, aso known as "acute accent" has its own utf-8 code and it is used to change the sound-values of the letters to which they are added.
The other symbols is an apostrophe, whose use is quite different to previous one.
That's because I believe there are some reasons to think that they are not using the same keycode but it's using a different keys configuration.
Take a look at this UTF-8 table:
https://www.utf8-chartable.de/unicode-utf8-table.pl
Accent: U+00B4
Apostrophe: U+0027
Please, review your keyboard to ensure it is correctly configured to differentiate both symbols.
In my case, with spanish keyboard configuration, I'm able to display both as follows:
Soy Rubén (spanish example)
I'm Rubén (english translation)
I'd like to access unusual letters such as Đ, Ħ, Ŋ or Ř directly from the keyboard on Windows (I can't copy-paste in the context I intend to use them).
However my Character Map shows blanks where they should appear, and (presumably for this reason) the Alt+ combinations don't work.
Why can't I type characters that evidently exist, seeing as I can copy them?
Example : if I type alt+331, which should give lowercase ŋ, I get K; in fact all alt+ beyond 256 seem to act mod 255.
This is bothering me more than it might seem, so thanks for any answer.
What is the purpose of the Unicode Character 'BACKSPACE' (U+0008) in programming? What applications can it be used for?
On output to a terminal, it typically moves the cursor one position to the left (depending on settings). On input, it typically erases the last entered character (depending on the application and terminal settings), though the DEL / DELETE character is also used for this purpose. Typically it can be entered by pressing Backspace or Control-H
Note that its action of deleting characters occurs only on a display, not in memory. A string within a running program can contain just about any sequence of characters (depending perhaps on the language), including backspace. In that context, it's generally just another character. For example, in C strlen("abcd\b") is 5, not 3.
In C and a number of other languages, it's represented in program source as '\b'. It's sometimes displayed as ^H.
All this applies whether it's represented as Unicode or not. The backspace character is common to most or all character sets: ASCII, Latin-1, the various Unicode representations -- even EBCDIC has a backspace character (but with a different code).
Can someone please tell me how to determine the unicode character point of a multi-key combination that includes the "command" key? For example, if a user presses the "command" key and "1" key on the keyboard at the same time, what is the unicode character representation for that?
Maybe I'm searching on the wrong thing, but I am not able to locate this in the character maps, keyboard references, or unicode tables I find. I can sort out other key combinations (e.g. shift-1) as there is an obvious character output of "!" that I can look up and find that it is U+0021. When I go to character maps or applications the command key always seems to take an action rather than output a character result to screen.
My app is for iOS, which I would expect to be the same as Mac OS X in terms of the unicode code point. All of the iOS APIs that provide access to the keyboard see it as a source of Unicode characters. Thus the reason I am trying to detect keystrokes this way.
Thanks.
Keyboard codes are basically independent of character codes.
While (as you mention) many keys have standard mappings to standard ASCII codes, it is up to the application to decide what to do with them.
Some input API's may be widely used on a particular OS, and some applications (e.g., terminal emulators) may be used as a common input method for a class of tasks, but there is no universal standard.
Obligatory wikipedia link for Unicode input.
You can't. There simply are no Unicode codepoints that correspond to Command + some-other-character.
The same is true of Shift, by the way. The fact that your computer happens to map certain combinations to certain Unicode codepoints does not imply that Unicode specifies such mappings, or that mappings exist for every combination of keys, or that those mappings are the same for everyone else. I use two keyboards every day; one of them maps Shift+3 to #, the other maps it to £. This is decided by the operating system, not by Unicode. If you tried to detect a Shift+3 keypress by listening for #, your program would seem to me to be broken half the time.
This is a perfect example of an XY question. You don't really care about Unicode -- what you really want to know is how to detect keypresses with the Command modifier on iOS. You should just have asked how to do that! There is probably an API that does exactly what you need that you have simply missed, because you were concentrating on your assumption that the solution would involve Unicode -- and there are probably numerous iOS experts who have not bothered to read this question at all, because they thought your problem related to Unicode rather than iOS.
Simple answer: no.
You haven't told us what sort of computer you are using. Mapping a key press to a Unicode code point is operating system specific, and then it depends on the locale that is active.