Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Guides   Examples
New in version: 8.2   8.3   8.4   8.5   9.0   9.1   9.2   9.3   9.4   9.5    Statistic  


Registers a global hot key based on the virtual key code and modifiers.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
HotKey 5.0 Yes Yes No No No
MBS( "HotKey.Register"; Code; Modifiers { ; Exclusive; FileName; ScriptName; Local; Name; Tag } )   More


Parameter Description Example value
Code The virtual key code of the key to watch. Can be number or name of key. "F5"
Modifiers The keyboard modifiers to look for. Can be number of text. Text can include command, shift, alpha, option and control.
Added in 6.2 for Windows: RightShift, RightOption and RightControl.
Exclusive Optional
Pass 1 to register exclusive or 0 for non exclusive.
FileName Optional
The database file name where the script is located.
ScriptName Optional
The script name.
Local Optional
Pass 1 to have hotkey only run script if FileMaker is frontmost. Else pass 0 (default) to have a global hotkey.
Name Optional
The name for the hotkey.
e.g. you can use this property to later decide in a script what to do.
"Test Hotkey"
Tag Optional
The tag for the hotkey.
e.g. you can use this property to later decide in a script what to do.


Returns reference or error.


Registers a global hot key based on the virtual key code and modifiers.
Only one such combination can exist for the current application, i.e. multiple entities in the same application cannot register for the same hot key combination. The same hot key can, however, be registered by multiple applications. This means that multiple applications can potentially be notified when a particular hot key is requested.
You can request exclusive registration for your process by passing 1 for exclusive parameter.
Please use HotKey.SetScript to assign a script for the hotkey or use parameters here.

Added Windows support with version 5.2.

With plugin version 6.0 or newer the script name can be a script ID number. In that case the plugin queries the script name for the given script ID. This allows to call scripts by ID and avoid problems if scripts are later renamed.


Register Control-F5:

Set Field [HotKeys::HotKey ID; MBS("HotKey.Register"; "F5"; "control")]
Set Variable [$r; Value:MBS("HotKey.SetScript"; HotKeys::HotKey ID; Get(FileName); "HotkeyAction")]

Register key 37 (L on US keyboard) with modifiers:

Set Field [HotKeys::HotKey ID; MBS("HotKey.Register"; 37; "shift-control-command-option")]
Set Variable [$r; Value:MBS("HotKey.SetScript"; HotKeys::HotKey ID; Get(FileName); "HotkeyAction")]

Register Control-F5 for showing/hiding data viewer:

Set Variable [$hotkey; Value:MBS("HotKey.Register"; "F5"; "control")]
Set Variable [$r; Value:MBS( "HotKey.SetEvaluate"; $hotkey; "MBS(\"Menubar.RunMenuCommand\"; 49297)" )]
// Mac & Windows

Register Control-F5 to write text file on desktop with content of data viewer:

MBS( "HotKey.SetEvaluate";
    MBS("HotKey.Register"; "F5"; "control");
    "MBS( \"Text.WriteTextFile\";
        MBS( \"FM.DataViewerContent\" );
        MBS( \"Path.AddPathComponent\";
            MBS( \"Folders.UserDesktop\" );
            \"Data Viewer \" & substitute(substitute(Get(CurrentTimestamp); \":\"; \"-\"); \"/\"; \"-\") & \".txt\" );
// Mac only.

Register Control-F6 to write current script a text file to desktop:

MBS( "HotKey.SetEvaluate";
    MBS("HotKey.Register"; "F6"; "control");
    "MBS( \"Text.WriteTextFile\";
        MBS( \"ScriptWorkspace.ScriptText\" );
        MBS( \"Path.AddPathComponent\";
            MBS( \"Folders.UserDesktop\" );
            \"Script \" & substitute(substitute(MBS( \"ScriptWorkspace.CurrentTab\" ); \":\"; \"-\"); \"/\"; \"-\") & \".txt\" );
// Mac only

Register hotkey Control-F7 for Windows to insert XML snippet:

MBS( "HotKey.SetEvaluate"; MBS("HotKey.Register"; "F7"; "control");
"Let ([
xml = \"<fmxmlsnippet type=\\\"FMObjectList\\\"><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"><Text>loop counting up from 1 to $count</Text></Step><Step enable=\\\"True\\\" id=\\\"141\\\" name=\\\"Set Variable\\\"><Value><Calculation><![CDATA[\\\"/* add count here */\\\"]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$count</Name></Step><Step enable=\\\"True\\\" id=\\\"141\\\" name=\\\"Set Variable\\\"><Value><Calculation><![CDATA[1]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$index</Name></Step><Step enable=\\\"True\\\" id=\\\"68\\\" name=\\\"If\\\"><Calculation><![CDATA[$index ≤ $count]]></Calculation></Step><Step enable=\\\"True\\\" id=\\\"71\\\" name=\\\"Loop\\\"></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"><Text>your script steps here</Text></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"></Step><Step enable=\\\"True\\\" id=\\\"89\\\" name=\\\"# (comment)\\\"><Text>next</Text></Step><Step enable=\\\"True\\\" id=\\\"141\\\" name=\\\"Set Variable\\\"><Value><Calculation><![CDATA[$index + 1]]></Calculation></Value><Repetition><Calculation><![CDATA[1]]></Calculation></Repetition><Name>$index</Name></Step><Step enable=\\\"True\\\" id=\\\"72\\\" name=\\\"Exit Loop If\\\"><Calculation><![CDATA[$index > $count]]></Calculation></Step><Step enable=\\\"True\\\" id=\\\"73\\\" name=\\\"End Loop\\\"></Step><Step enable=\\\"True\\\" id=\\\"70\\\" name=\\\"End If\\\"></Step></fmxmlsnippet>\";
r = MBS( \"Clipboard.SetFileMakerData\"; \"ScriptStep\"; xml );
r = MBS( \"RemoteControl.PressControlKey\"; 1 );
r = MBS( \"RemoteControl.PressKey\"; \"v\");
r = MBS( \"RemoteControl.PressControlKey\"; 0 )
]; 1 )"; 0 )
// for Windows

See also

Example Databases

Created 4th February 2015, last changed 20th November 2019

HotKey.List   -   HotKey.SetEnabled

Feedback: Report problem or ask question.

MBS FileMaker Plugins