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.
Related
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
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).
I was wondering if Visual Basic could emulate the pressing of keys.
I was thinking of a program that did this:
When I press a button (Button1) it would start a timer (Timer1), then press the V key on the keyboard and then type what was entered in a textbox (Textbox1), then press the Enter key. After doing that, repeating that action a second or two later, but saying what is in (Textbox2).
Could this be possible? If yes, please respond.
This will tell you how:
http://msdn.microsoft.com/en-us/library/ms171548(v=vs.80).aspx?cs-save-lang=1&cs-lang=vb
And use:
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx?cs-save-lang=1&cs-lang=vb
For special keys.
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.
I have a keyboard event listener, and I am listening for the number pad key codes (1 through 9) for when number lock is activated; this works fine. However, in my app I also want to allow usage of a modifier key (CTRL) along with the number pad keys. The strange thing is that when holding CTRL, pressing 1 or 3 does not generate any keyboard event whatsoever, whereas 2 and 4 - 9 do generate the expected events. I have seen other references to this issue after some Googling, so I do not believe this is necessarily Flash-specific, but I have yet to find any answers.
I tried using SHIFT as a modifier, but that just results in generating the key codes from the number pad as if number lock was off (eg, SHIFT+Numpad1 returns the End keycode, regardless of number lock state) - apparently this is intentional Windows behavior. ALT is not an option with the numpad due to altcodes.
Any ideas on how to get CTRL+Numpad1 and CTRL+Numpad3 to generate the keyboard events? Or any explanation as to why they don't?
Edit: I tried out using these key combinations in Firefox as enriquein suggests below, and all the key combinations work A-OK, leading me to believe that this is likely a Flash-specific issue, or at least not a hardware issue.
I have run into issues in the past with numpad keys on specific keyboards. Various key combinations fail to register on specific keyboards, and it is possible that the keyboard you are using may just not be generating any event in that case. It's not guaranteed to work, but I would recommend trying out a different keyboard (different vendor, etc) and see if that works. It also might be an issue with localized keyboards, if you are using a non-english keyboard.
I'm almost certain it's not Flash related because I had similar problems with a localized keyboard and could not get it to generate events at all for certain keys or key combinations.
Try enumerating all key events and searching trough what they're mapped to, or google evtest.c, compile it and run it and see what it has to say.
Indeed it looks like its keyboard specific. I tried the key combinations as I read this question in Firefox and they triggered the same event as pressing Ctrl+Number (which is switch to tab #Number).
This was using a standard US/101-key english keyboard (no extra media buttons or anything).
Some keyboards don't register certain key combinations. I think that this is down to how they are put together. For example some may register left hand Ctrl + key combination but not right Ctrl + same key!
A work around would be to detect the key down and key up events for the Ctrl key.
You could then raise a custom event for Ctrl + numpad key or work with a volatile flag to show the Ctrl key state.