Class 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());
}
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidfireHotkey(int id) Called by the port on the EDT when a shortcut is pressed.static booleanisGlobal()True when shortcuts fire while another application has the focus.static booleanTrue when shortcuts can be registered.static intregister(char key, int modifiers, ActionListener listener) Registers a shortcut.static voidsetImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use onlystatic voidunregister(int id) Removes a shortcut.
-
Field Details
-
MOD_CTRL
public static final int MOD_CTRLThe Control key.- See Also:
-
MOD_SHIFT
public static final int MOD_SHIFTThe Shift key.- See Also:
-
MOD_ALT
public static final int MOD_ALTThe Alt (Option) key.- See Also:
-
MOD_META
public static final int MOD_METAThe Command (Windows, Super) key.- See Also:
-
-
Method Details
-
setImplementation
public static void setImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use only
Parameters
impl: 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
Registers a shortcut.
Parameters
key: an ASCII letter or digit; letters are matched without casemodifiers: a mask of theMOD_constants, at least onelistener: called on the EDT when the shortcut is pressed
Returns
an identifier for
#unregister(int), or -1 when the platform did not register it -
unregister
public static void unregister(int id) Removes a shortcut.
Parameters
id: 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
id: the identifier the shortcut was registered with
-