AboutSupportDeveloper GuideVersion 35.120.79.7

The GlobalHotkey module can register/unregister a global hotkeys.

Hierarchy

Accessors

  • get me(): Identity
  • Provides access to the OpenFin representation of the current code context (usually a document such as a View or Window), as well as to the current Interop context.

    Useful for debugging in the devtools console, where this will intelligently type itself based on the context in which the devtools panel was opened.

    Returns Identity

Methods

  • Returns (string | symbol)[]

  • Checks if a given hotkey has been registered by an application within the current runtime.

    Parameters

    • hotkey: string

      a hotkey string

    Returns Promise<boolean>

    Example

    const hotkey = 'CommandOrControl+X';

    fin.GlobalHotkey.isRegistered(hotkey)
    .then((registered) => {
    console.log(`hotkey ${hotkey} is registered ? ${registered}`);
    })
    .catch(err => {
    console.log('Error unregistering the hotkey', err);
    });
  • Parameters

    • type: string | symbol

    Returns number

  • Parameters

    • type: string | symbol

    Returns Function[]

  • Adds a one time listener for the event. The listener is invoked only the first time the event is fired, after which it is removed.

    Type Parameters

    • EventType extends "registered" | "unregistered"

    Parameters

    Returns Promise<GlobalHotkey>

    Remarks

    Event payloads are documented in the Events namespace.

  • Adds a listener to the beginning of the listeners array for the specified event.

    Type Parameters

    • EventType extends "registered" | "unregistered"

    Parameters

    Returns Promise<GlobalHotkey>

    Remarks

    Event payloads are documented in the Events namespace.

  • Adds a one time listener for the event. The listener is invoked only the first time the event is fired, after which it is removed. The listener is added to the beginning of the listeners array.

    Type Parameters

    • EventType extends "registered" | "unregistered"

    Parameters

    Returns Promise<GlobalHotkey>

    Remarks

    Event payloads are documented in the Events namespace.

  • Registers a global hotkey with the operating system.

    Parameters

    • hotkey: string

      a hotkey string

    • listener: ((...args) => void)

      called when the registered hotkey is pressed by the user.

        • (...args): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Promise<void>

    Throws

    If the hotkey is reserved, see list below.

    Throws

    if the hotkey is already registered by another application.

    Remarks

    The hotkey parameter expects an electron compatible accelerator and the listener will be called if the hotkey is pressed by the user. If successfull, the hotkey will be 'claimed' by the application, meaning that this register call can be called multiple times from within the same application but will fail if another application has registered the hotkey.
    The register call will fail if given any of these reserved Hotkeys:

    • CommandOrControl+0
    • CommandOrControl+=
    • CommandOrControl+Plus
    • CommandOrControl+-
    • CommandOrControl+_
    • CommandOrControl+Shift+I
    • F5
    • CommandOrControl+R
    • Shift+F5
    • CommandOrControl+Shift+R

    Raises the registered event.

    Example

    const hotkey = 'CommandOrControl+X';

    fin.GlobalHotkey.register(hotkey, () => {
    console.log(`${hotkey} pressed`);
    })
    .then(() => {
    console.log('Success');
    })
    .catch(err => {
    console.log('Error registering the hotkey', err);
    });
  • Removes all listeners, or those of the specified event.

    Parameters

    • Optional eventType: "registered" | "unregistered"

    Returns Promise<GlobalHotkey>

  • Remove a listener from the listener array for the specified event.

    Type Parameters

    • EventType extends "registered" | "unregistered"

    Parameters

    Returns Promise<GlobalHotkey>

    Remarks

    Caution: Calling this method changes the array indices in the listener array behind the listener.

  • Unregisters a global hotkey with the operating system.

    Parameters

    • hotkey: string

      a hotkey string

    Returns Promise<void>

    Remarks

    This method will unregister all existing registrations of the hotkey within the application. Raises the unregistered event.

    Example

    const hotkey = 'CommandOrControl+X';

    fin.GlobalHotkey.unregister(hotkey)
    .then(() => {
    console.log('Success');
    })
    .catch(err => {
    console.log('Error unregistering the hotkey', err);
    });
  • Unregisters all global hotkeys for the current application.

    Returns Promise<void>

    Remarks

    Raises the unregistered event for each hotkey unregistered.

    Example

    fin.GlobalHotkey.unregisterAll()
    .then(() => {
    console.log('Success');
    })
    .catch(err => {
    console.log('Error unregistering all hotkeys for this application', err);
    });