Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class GlobalHotkeys
- Object
- GlobalHotkeys
Keyboard shortcuts that fire while the application runs. Where the
platform allows it the shortcut is system wide and fires while another
application has the focus; #isGlobal() says which. The Java SE desktop
build registers application wide shortcuts that fire while any of its
windows has the focus. Mobile platforms answer false from
#isSupported().
if (GlobalHotkeys.isSupported()) {
int id = GlobalHotkeys.register('K', GlobalHotkeys.MOD_CTRL | GlobalHotkeys.MOD_SHIFT,
new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Log.p("Hotkey pressed");
}
});
Log.p("Registered " + id + ", global " + GlobalHotkeys.isGlobal());
}Fields
public static final int MOD_CTRL = 1 | The Control key. |
public static final int MOD_SHIFT = 2 | The Shift key. |
public static final int MOD_ALT = 4 | The Alt (Option) key. |
public static final int MOD_META = 8 | The Command (Windows, Super) key. |
Methods
public static void setImplementation(CodenameOneImplementation impl) | Invoked internally from Display, this method is for internal use only |
public static boolean isSupported() | True when shortcuts can be registered. |
public static boolean isGlobal() | True when shortcuts fire while another application has the focus. |
public static int register(char key, int modifiers, ActionListener listener) | Registers a shortcut. |
public static void unregister(int id) | Removes a shortcut. |
public static void fireHotkey(int id) | Called by the port on the EDT when a shortcut is pressed. |
Inherited methods
Field details
MOD_CTRL
public static final int MOD_CTRL = 1The Control key.
MOD_SHIFT
public static final int MOD_SHIFT = 2The Shift key.
MOD_ALT
public static final int MOD_ALT = 4The Alt (Option) key.
MOD_META
public static final int MOD_META = 8The Command (Windows, Super) key.
Method details
setImplementation
public static void setImplementation(CodenameOneImplementation impl)Invoked internally from Display, this method is for internal use only
Parameters
implCodenameOneImplementation- implementation instance
isSupported
public static boolean isSupported()True when shortcuts can be registered.
Returns
true on a desktop platform
isGlobal
public static boolean isGlobal()True when shortcuts fire while another application has the focus.
Returns
true for system wide shortcuts
register
public static int register(char key, int modifiers, ActionListener listener)Registers a shortcut.
Parameters
keychar- an ASCII letter or digit; letters are matched without case
modifiersint- a mask of the
MOD_constants, at least one listenerActionListener- called on the EDT when the shortcut is pressed
Returns
an identifier for
#unregister(int), or -1 when the platform did not
register itunregister
public static void unregister(int id)Removes a shortcut.
Parameters
idint- the identifier
#register(char, int, ActionListener)answered
fireHotkey
public static void fireHotkey(int id)Called by the port on the EDT when a shortcut is pressed. Not meant
for application code.
Parameters
idint- the identifier the shortcut was registered with