There's an action in my program which users need to perform very frequently (potentially hundreds of times per session), and I'd like to add a keyboard shortcut for users with a bluetooth keyboard. Is there any way to do this?
Right now, the closest I've come is triggering the action whenever the U+F8FF character is entered (Shift+Alt+k on an iPad/iPhone/Mac, which prints an apple logo character) in a text view. Of course, this would present an issue if the user actually wanted to input an apple symbol.
Are there any better ways to support keyboard shortcuts (hopefully Cmd+something, rather than Shift+Alt+something)? Thanks!
Under Cocoa for Mac OS X, you would gather modifier key information from the NSEvent passed to the keyDown: method in an NSResponder object. CocoaTouch replaces the NSResponder with UIResponder and NSEvent with UIEvent. The UI versions don't have documented keyboard event support. I'm guessing that Apple has extended UIResponder to handle keydown events, but hasn't publicly documented the changes yet. Unfortunately that means we'll just have to wait for that documentation to be able to read the modifier keys.
I think your current solution is a fine solution until Apple gives us a keyboard supporting UIResponder.
Related
I'm writing a game in Swift 3 for Mac OS. I'd like to be able to do "as long as the A key is down, move to the left". In other environments I'm used to a function like KeyIsDown('A'), but I can't find it here.
Does it exist, or do I need to watch every keydown and keyup event and keep track of the state myself? I will be wanting to do this for arrow keys as well as alphabetic keys.
Kudos to BallpointPen, for a clear answer. So I'll just keep a table of key state for every keycode, and switch bits on an off as keyDown and keyUp events come in.
Depending on you use UITextview or UITextfield. So, conforming UITextviewDegelate or UITextfieldDegalate there are some degelate methods that can change keyboard state.
I have a very basic OS X that has a few different elements.
A text field, a table view and a file contents view.
I have a single ViewController.
I'd like to be able to intercept specific key events for each of these elements in the storyboard in my ViewController and change the focus between the different elements.
For example, if the cursor is currently in the file contents view, and I hit ESCAPE, I'd like for the focus to be transferred to the text field.
Or, if the focus is currently on the table view and I hit ENTER, that the cursor/focus is moved to the file contents view.
What's the best way to handle this?
I have tried overriding the keyDown method in the ViewController but with things such as autocomplete getting in the way, I'm not having much luck. I have added a print statement to keyDown to check if the function is receiving events, but it's not always fired.
Update
Except for the specific keys that I want to intercept, I want all other key events to behave as normal. For example, typing in the file contents view, or the text field.
I would highly recommend watching the WWDC talk #145 from 2010, Key Event Handling in Cocoa Applications. It gives an overview of the event delivery mechanism, and several ways of handling events:
Make a menu item or button whose keyEquivalent is the escape key.
Override cancelOperation(_:) or complete(_:), which are the two NSResponder methods which can get invoked by default when the escape key is pressed. (There are other methods for the enter/return key.)
Override sendEvent(_:) in NSApplication or NSWindow to intercept all events and bypass the default behavior.
I have one question, may be it is very simple, but I do not know about this nothing...
For example, I have an application, application with textfield, I want to know two things.
First: Is possible to switch keyboard when application in runtime?
Second: how I can switch type of keyboard(Russian, English, Swedish, etc.) in my application*?
*-without going to Settings->General->Keyboard->add new keyboard.
Not sure about changing languages (I did find this other post about it: change input source language programmatically OSx), but changing the keyboard is pretty easy. Here is a one line example:
textField.keyboardType = UIKeyboardTypeURL;
Take a look at the UITextInputTraits protocol reference for more info. Then the question comes in where to implement this. I am assuming that you want to check conditions right before the keyboard comes up, you may have to implement UITextFieldDelegate protocol (and maybe using the field's tag to see which field the cursor is in).
Hope this helps.
The iPad virtual keyboard will disappear in one of (at least) these 3 circumstances:
If the control (say, a UITextField) programmatically resigns first responder.
If the user taps the "dismiss keyboard" button in the lower right.
If the user connects to the USB/keyboard dock peripheral.
In all cases, I get the UIKeyboardWillHideNotification.
The problem is that the first two cases are generally equivalent-- in other words, the user is done editing the text field. But in the third case, the text field is still being edited, just from another input source.
The problem is detecting the difference between cases 2 and 3. All I get in both cases is UIKeyboardWillHideNotification. In case 2, I generally want to also lock the edit control and commit the value. In case 3, I generally want to do nothing and allow editing to continue.
But how can I tell the difference?
Apple's Pages app seems to be able to distinguish this on document-title renaming.
I would look at the UIKeyboardBoundsUserInfoKey passed with the notification. The physical keyboard probably has empty bounds.
It sounds like you're just trying to figure out when a user is done editing. You could listen for the UITextFieldTextDidEndEditingNotification notification for cases 1 and 2.
A much simpler solution would be couldn't you just check against the editing property of UITextField to determine if it's still supposed to be editing or not? I don't have a physical keyboard, so I have no way to test this. I'm just guessing.
Here's a link to the documentation on that property: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITextField_Class/Reference/UITextField.html#//apple_ref/occ/instp/UITextField/editing
I'm very curious to know if this works or not... :)
I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values varies. The problem is that the number pad does not contain a key for entering a decimal point.
When I lock my phone, the number pad that comes up to enter a passcode has a custom button to make an emergency call (as seen in the following screenshot):
Numberpad with custom button http://img25.imageshack.us/img25/6426/photoejg.jpg
Does anyone know how to create a number pad with a decimal point button or a custom button (like the emergency call button above)?
Thanks.
There's no Apple-approved way to edit the existing keyboard. If you want them to allow it, file a feature request.
That said, it just so happens that in most applications the keyboard (instance of UIKeyboard) is a separate UIWindow, and you can iterate over the windows in the application and start adding custom subviews that respond to the appropriate touch actions. Find it by iterating over [[UIApplication sharedApplication] windows] and checking to see if the description contains the string UIKeyboard. For more info on this method and some sample code, see this answer.
Another approach is to create your own custom view and build a keyboard from scratch. Be careful if you do this, though, as it requires a lot of manual work, not only in creating the keyboard and getting the touch behavior to match Apple's, but also in any control you add that would bring up the regular keyboard - you'll need to redirect things like becomeFirstResponder to show your own keyboard, rather than Apple's.
Edit: As ZaBlanc pointed out, newer versions of iOS have a way to do this with the inputView and inputAccessoryView properties. See the UIResponder class reference for details.
set UIKeyboardType to UIKeyboardTypeDecimalPad
Available in iOS 4.1 and later.
Create a UIViewController that contains a UIView with a bunch of buttons. Now your keyboard can have whatever you want on it.