Esc and Enter keys in Cocoa dialog - cocoa

How can I dismiss dialog in Cocoa application when user presses Esc or Enter key? I have OK button, is it possible to make it default button?

If you present the alert panel using the NSAlert class or, NSRunAlertPanel family of functions, or the NSBeginAlertSheet family of functions, you will get support for default and cancel buttons automatically.
If you're presenting a sheet that needs OK/Cancel buttons, and you're not using any of the above, you should be able to assign your buttons appropriate keyboard equivalents in Interface Builder using the attributes inspector. (Just highlight the Key Equiv. area and press the key you want to be equivalent to pressing that button.)
If you're presenting a dialog that's not either an alert or a document/window-modal sheet — don't. :) Document-modal alerts aren't Mac-like, and shouldn't be used for things like preferences windows.

Just assign the "escapeKey" or "cancelKey" in the IB in the property "key equivalent" for the buttons you want and it will work fine. Also if you assign that keys the buttons gets a different highlighting.

Related

Keyboard navigation for RadListBox with icons

I am using RadListBox to show a list of items. Each item has an icon. The requirement is jumping on the item when a the first letter of that item is pressed.
For example: It should focus on "Dock" when letter "D" is pressed
Is there any built-in feature to accomplish this>
This functionality is built into the RadListBox right out of the box.
You must have the list box focused and then type a key to select the item with the first letter matching the key that was pressed. In order to focus on the list box you can either: click with the mouse, tab to it, set focus in JS, or use the KeyboardNavigationSettings.CommandKey and KeyboardNavigationSettings.FocusKey to help aid with keyboard navigation.
Example:
RadListBox1 = new RadListBox()
RadListBox1.KeyboardNavigationSettings.CommandKey = KeyboardNavigationModifier.Alt;
RadListBox1.KeyboardNavigationSettings.FocusKey = KeyboardNavigationKey.L;
You can also use EnableMarkMatches to highlight more than one match if necessary and for typing more than one letter for selecting.
Reference: Telerik RadListBox Keyboard Navigation Demo << This has all the sample code you should need.
Seems this a Telerik bug, but i made a project, test situation and it's working.
download sample project here.
this project tested on google chrome Version 60.0.3112.113 (Official Build) (64-bit)
After run project press Alt+s or Alt+o or Alt+c
Remember change AccessKey property to change shortcut key:
RadListBox1.Items[0].AccessKey = "s";
I should say that this NOT a perfect solution.
RadListBox is a powerful ASP.NET AJAX control to display a list of items. It allows for multiple selection of items, reorder and transfer between two listboxes. Drag and drop is fully supported as well.

Keyboard Extension - Find out if user did Copy/Cut/Select

In Keyboard Extension, in UIInputViewController, I can get notified through textDidChange(textInput: UITextInput) of any change, and use self.textDocumentProxy.documentContextBefore/AfterInput to get current text.
Problem arise when user 'select text'. The 'before' and 'after' "sees" only the part before and after selection.
Is there any way to know if user touched any of the Copy-Cut-Select in a textField (given - we don't have access to that field from Keyboard Extension)?
Something like:
if(self.textDocumentProxy.someProperty == UIDocumentProxyTextCut)
Or any other way to know which of the UITextField action (Copy/Cut/Select) did the user took?
I think we can not find out if user touched on Copy/Cut/Paste menu
Because a custom keyboard can draw only within the primary view of its
UIInputViewController object, it cannot select text. Text selection is
under the control of the app that is using the keyboard. If that app
provides an editing menu interface (such as for Cut, Copy, and Paste),
the keyboard has no access to it. A custom keyboard cannot offer
inline autocorrection controls near the insertion point.
Source: https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html
P/s:
I saw self.textDocumentProxy.documentContextAfterInput is always NIL. Who know why?
How can we know where the cursor is to provide suggestion for user?

return key generates IDOK for button with focus

I did a SetFocus to a button in a dialog. The button gets the dashed outline. When the user presses the return key, the dialog get a IDOK message rather than a message from the button were I set the focus. The same thing happens under other circumstances.
Why is this happening? And how can I cause the return to act as a button press?
Plain c++ windows app, no MFC, no NET.
Feature, not a bug. The [Enter] key operates the button that's marked as the default button for a dialog. Either with the DEFPUSHBUTTON in the .rc file or the BS_DEFPUSHBUTTON style flag. Which is typically the "OK" button so getting IDOK back is expected. The [Escape] key is special that way too, typically the [Cancel] button. This is bound to ring a bell if you think back on how you used dialogs before.
You click a button that has the focus by pressing the space bar instead.
In another SO question I found KB article that might help you:
If a dialog box or one of its controls currently has the input focus,
then pressing the ENTER key causes Windows to send a WM_COMMAND
message with the idItem (wParam) parameter set to the ID of the
default command button. If the dialog box does not have a default
command button, then the idItem parameter is set to IDOK by default.
When an application receives the WM_COMMAND message with idItem set to
the ID of the default command button, the focus remains with the
control that had the focus before the ENTER key was pressed. Calling
GetFocus() at this point returns the handle of the control that had
the focus before the ENTER key was pressed. The application can check
this control handle and determine whether it belongs to any of the
edit controls in the dialog box. If it does, then the user was
entering data into one of the edit controls and after doing so,
pressed ENTER. At this point, the application can send the
WM_NEXTDLGCTL message to the dialog box to move the focus to the next
control.
According to MSDN,
Dialog Box Keyboard Interface
The system provides a special keyboard interface for dialog boxes that carries out special processing for several keys. The interface generates messages that correspond to certain buttons in the dialog box or changes the input focus from one control to another. Following are the keys used in this interface and their respective actions.
...
ENTER: Sends a WM_COMMAND message to the dialog box procedure. The wParam parameter is set to IDOK or control identifier of the default push button.
Since the system intercepts and processes ENTER key pressed directly through the dialog, you'll need to handle it in your dialog box procedure by calling GetFocus() to first see which control has the focus, and perform the appropriate action for that particular control.

Can keyboard have done and cancel buttons?

Im trying to create a password page similar to the one that opens up when you click Lock+wallpaper in the settings of the Windows Phone.
How ever I could not find a keyboard with the done and cancel, a done and cancel buttons along with the numeric keyboard is visible in the lock+wallpaper page when you toggle the password switch.
How do I get one similar to that? As as alternative I tried to create done and cancel buttons, but the problem is, the keyboard overlaps these buttons where as in the lock+wallpaper page, the keyboard stays and does not overlap the button.This should mean that the buttons are present along with the keyboard right?
Could anyone help me on this one?
There is no InputScope which add "done" or "cancel" buttons to the SIP.
Instead you should look to use the ApplicationBar and add buttons for each of these functions. FOr doen you could use an image of a tick or a save icon for "done" and a cross for "cancel".
Be careful not to add a Cancel button if you really don't need one as the hardware back button would suffice instead.

GUI: should a button represent the current state or the state to be achieved through clicking the button?

GUI: should a button represent the current state or the state to be achieved through clicking the button?
I've seen both and it sometimes misleads the user. what do you think?
The label on the button should reflect what the button does, i.e. it should describe the change the button makes.
For example, if you have a call logging system a button should say "Close Call" and the user can click it to close the call. The button should not have the label "Call is Open" and the user clicks to change the call status as that's very counter-intuitive, since the button is effectively doing the opposite to what it says on it.
In my opinion the label - and so the function - of a button should rarely, if ever, change. A button is supposed to be a like a physical button and they usually only do a single thing. (There are a few exceptions like play-pause on a media player where it's OK for the button label/icon to change, but at least this is copying a button from a real physical device.)
To carry on the example from above, I would say usually you would want two buttons, "Open Call" and "Close Call" and disable whichever one is not appropriate. Ideally you'd have a field elsewhere displaying the status of the call.
In summary, buttons are for doing things not for passing on information to the user.
The button should represent the action to be executed, not the state.
Some buttons are actions and are not ambiguous, like "Save", "Print" or "Enable user".
When a button represents a state that can be toggled, like Enable and Disable something, I do one of the following:
Change the button text, and make it always point to the state that will be achieved; (i.e. make the button point to actions, not states);
- Keep the button's text the same, but use one of those sticky buttons that will stay pressed, representing that the current state is "on" or "off". I prefer the former approach, though.
It should represent the action taken when clicking the button. States should always be presented by other means.
But I know what you mean. My car radio has buttons with text that shows the current state. It is really confusing.
This depends on the function which will be triggerd by the button click.
if the click changes the state of an entity i would suggest that the button represents the state the entity will enter after clicking the button
if the click triggers some kind of functionality the button should represent the function.
The appearance of the button is also a clue to its state. It should follow the standards of the environment if any exist (example, beveled edge / shadow appears on mouse click in Windows).

Resources