iPad Keyboard: mode based key augmentation - cocoa

When using the "add Account..." function in the 'Mail,Contacts, Calendars' section in 'Settings' on an iPad, selecting the address field causes the keyboard to change the labels of the !, and ?. keys, shorten the right '.?123' and space key and add two new keys (_ and -)
I have also seen the Keyboard augment to show a .com key for URLs.
Im guessing you can pass the keyboard a 'url mode' or 'email address mode' type argument, has anyone manipulated the keyboard in such a way before and what degree of plasticity is there for actual labels or modes?

There are a number of defined UIKeyboardType's. You must use one of those.

Related

Standard (no third-party) way to get numeric keypad working as arrow keys on macOS (Xcode? hidutil?)

I always use numeric keypad as arrows, as I find it more convenient than using an separate arrow pad. Until recently I used a tool Karabiner Elements, but it stopped functionning at Big Sur.
Yes, The Karabiner developer is working on that issue, but it will be better to solve it without relying on a third-party tool.
It will be enough for me to either remap Xcode, or (which is preferred) to change key bindings in the system, using a tool like hidutil.
Xcode's Preferences - Key Binding has a section Text - Section. When I try to modify the binding for say Move Down by pressing Down arrow on numeric keypad it comes up as '2'. Now whereever I press '2', on keyboard or numeric keypad, it always works as Move Down which is certainly not what I am after.
About hidutil. I couldn't find a good manual or any example of keyboard mapping.
Any help?
Had another look at this article. Here is the answer:
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x70000005A,"HIDKeyboardModifierMappingDst":0x700000051},
{"HIDKeyboardModifierMappingSrc":0x700000060,"HIDKeyboardModifierMappingDst":0x700000052},
{"HIDKeyboardModifierMappingSrc":0x70000005C,"HIDKeyboardModifierMappingDst":0x700000050},
{"HIDKeyboardModifierMappingSrc":0x70000005E,"HIDKeyboardModifierMappingDst":0x70000004F},
{"HIDKeyboardModifierMappingSrc":0x70000005F,"HIDKeyboardModifierMappingDst":0x70000004A},
{"HIDKeyboardModifierMappingSrc":0x700000061,"HIDKeyboardModifierMappingDst":0x70000004B},
{"HIDKeyboardModifierMappingSrc":0x700000059,"HIDKeyboardModifierMappingDst":0x70000004D},
{"HIDKeyboardModifierMappingSrc":0x70000005B,"HIDKeyboardModifierMappingDst":0x70000004E},
{"HIDKeyboardModifierMappingSrc":0x700000062,"HIDKeyboardModifierMappingDst":0x700000049},
{"HIDKeyboardModifierMappingSrc":0x700000063,"HIDKeyboardModifierMappingDst":0x70000004C}]}'
Still can't fugure out, how to do (if possible) complex mapping with modifier keys (eg Ctrl+PgUp to Home), but that's another topic.

NSMenuItem Key Equivalent set to Enter key from Number Pad

I want to set the Key Equivalent on an NSMenuItem to be the number pad's Enter key. I don't have a 10-key number pad on my desktop, but I was told that Function+Return on the main keyboard would emulate the Number Pad Enter key. However, when I try to do that in Interface Builder in the Key Equivalent field, my cursor just jumps to the next field.
How can I set, in Interface Builder, the number pad's Enter key to the Key Equivalent on an NSMenuItem?
If you'd like to provide the programmatic way to do it in the comments, that's fine and appreciated, but for full Answers to this question, please restrict them to doing it in Interface Builder.
It turns out that using Function+Return on my normal keyboard DID work to put the Keypad Enter key as the key equivalent. I went and got an extended physical keyboard that had a keypad. When I hit the Keypad Enter key in the Key Equivalent field, I got the same behavior I got when I hit the Function+Return. I tested it within the app and using Function+Return to set the key equivalent DID successfully bind that Menu Item to the Keypad Enter key... it's just that Xcode didn't SHOW that any key was really bound.

Hotkey field in XUL for Firefox

I have a Firefox extension written in XUL. It takes a hotkey. I want to have an input field where the user can press any key and I can programmatically determine what key was pressed.
I don't care about key combos which have meta meanings inside the OS (I don't need to capture Ctrl + Alt + Del).
If the key is already defined by Firefox, I'm OK with not capturing it (for instance, if the user presses F1 and help pops up instead of the key being captured, I'm fine).
I would also love to have some way to determine programmatically whether the key pressed already has some other meaning inside of Firefox, but that is likely out of scope for this request. I just mention it in case it's easy.
My current solution, which seems to have been adopted by a number of add-ons, is to provide a text box where the user can type a printable character and then a series of check boxes for modifier keys. This solution is barely workable but terrible for a number of reasons (it doesn't allow users to use non-printing keys such as function keys in their combos, it allows the user to input invalid characters (such as Unicode characters with no physical key on the keyboard), and it's just awkward to use).
Thanks!
You can use Inline Options
https://developer.mozilla.org/en-US/Add-ons/Inline_Options
You can detect the key pressed in the text input and write your modifiers like accel or alt.
Source example:
http://git.io/vez1o

User assigned key equivalents

I'm working on a Status Bar App. I'd like to allow the user to modify the menu item key equivalents to their own preferences. I've seen this done before it's a pretty common feature.
A prefs window usually has an area with textfields where the user enters their keyboard shortcut for specific menu items.
How does one setup the textfield so that it displays the modifier key fonts?
The default NSTextfield ignores modifiers.
Also I have yet to find an example project showing this functionality, if anyone has a link that would be very helpful.
You may wish to take a look at Shortcut Recorder which allows the user to record key equivalents using modifiers and then for you to retrieve them and set them for the NSMenuItem.
Once the user has recorder their shortcut/key combination you can access the SRRecorderControl's objectValue property which has values for the key code and modifier flags.
https://github.com/Kentzo/ShortcutRecorder
The modifier keys all have Unicode values that you can see in the "Special Characters" palette and they are displayed by the normal system font. Most of them are in the "Technical Symbols" category of the palette but the up-arrows for the Shift and Caps Lock keys are in the "Arrows" section.
You can insert these values when editing label elements in Interface Builder or Xcode, or include their corresponding Unicode values when creating something like an NSString object.
For example, the Shift key's UTF-8 sequence (as shown in the palette) is E2 87 A7 so one way to set it programmatically is to add those bytes to an array and create an NSString from the UTF-8 array. I prefer the array approach because it's "bulletproof"; it will always be interpreted as UTF-8 and do what you expect. If you try to insert characters directly into #"" or CFSTR() strings, you then have to make sure your source file's encoding is correct (and older versions of Xcode wouldn't even allow this, they'd assume ASCII only).

How to determine if a certain key is pressed, knowing only its position on U.S. keyboards?

Consider that, for a Windows video game, I need to determine if the key which generates the ` and ~ characters on the U.S. English keyboard layout (which is usually below the Escape key and left to 1) has been pressed. This may sound like a trivial question, but it doesn't seem like one to me.
When Windows sends keyboard messages, it specifies the virtual key code and the OEM scan code. We can't rely on the OEM scan code, because "the value depends on the OEM" - and nor can we depend on the virtual key code, because it depends on the currently active keyboard layout.
Our current "solution" is to use LoadKeyboardLayout and MapVirtualKeyEx to find the OEM scan code of the key that generates the ` character on the U.S. English keyboard layout, then just listen for that OEM scan code. The problem is that this doesn't work if the user doesn't have the U.S. English layout installed.
Is there a real way to do this on Windows?
The OEM scancode does not change from keyboard to keyboard. No reason not to use it.
Back in the DOS-days the same scancodes have been used for games because it has been the only way to detect key-up and key-down events. Noone had problems with it and I doubt it will change in the future.
If you want another option you may want to give DirectInput-API a try. It gives you the raw scancodes as well and if I'm not mistaken you can also query the physical position, dimension and whatnot of each key.
Tie the game action to the character, not the position of the key. Otherwise, how do you tell the user which key to press? "under the escape key"? They may not have anything there, but if you tell them "the ^ key", they can look for it.
You'll probably also want to make it configurable to accomodate exotic keyboard layouts and user preferences.

Resources