AboutSupportDeveloper GuideVersion 38.126.83.75

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 OpenFin.View or OpenFin.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[]

  • 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>

  • 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);
    });