Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
Registers a global hot key based on the virtual key code and modifiers.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
HotKey | 5.0 | ✅ Yes | ✅ Yes | ❌ No | ❌ No | ❌ No |
Parameter | Description | Example | Flags |
---|---|---|---|
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. |
"control" | |
Exclusive | Pass 1 to register exclusive or 0 for non exclusive. | 0 | Optional |
FileName | The database file name where the script is located. | "test.fmp12" | Optional |
ScriptName | The script name. | "MyScript" | Optional |
Local | Pass 1 to have hotkey only run script if FileMaker is frontmost. Else pass 0 (default) to have a global hotkey. | 0 | Optional |
Name | The name for the hotkey. e.g. you can use this property to later decide in a script what to do. |
"Test Hotkey" | Optional |
Tag | The tag for the hotkey. e.g. you can use this property to later decide in a script what to do. |
Optional |
Returns reference or error.
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\" );
\"UTF-8\"
)"
)
// 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\" );
\"UTF-8\"
)"
)
// 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
This function checks for a license.
Created 4th February 2015, last changed 15th May 2020