« MBS Xojo Plugins, ver… | Home | MBS FileMaker Advent … »

MBS FileMaker Advent calendar - Door 19 - Hot Keys

candy cane Monkeybread Monkey as an elf candy cane
Day 19 - Hot Keys

In Door 17 we got to know the UserNotifications, which we display once every time the solution is opened. But our little monkey doesn't think that's enough, so he wants to be able to call it up more often. However, he doesn't want an additional button on the layout, but would like to start the script automatically with a key combination. The HotKey functions under Mac and Windows are available in the plugin for this purpose. We can use them to define hotkeys to start scripts or calculations.

With the HotKey.Register function, we can register a specific key combination by first entering the virtual key code of the key to watch in the parameters. This can be the function keys (F), for example. So that the keys cannot fire if only this key is pressed, as otherwise normal use would not be possible, we also enter so-called keyboard modifiers. These can be the additional keys command, shift, alpha, option, control, RightShift, RightOption and RightControl. We can also specify other optional parameters in this function. For example, we can specify whether a hotkey should be exclusively assignable for this solution, which would prohibit other applications that also want to register this combination, because this combination is already assigned and can only be used again when this hotkey is released. Then we can also define the script in the parameters that is to be started when this combination is pressed. To do this, we specify the name of the database in which the script is located and the script name.

Set Variable [ $HotKey ; Value: MBS( "HotKey.Register" ; "F3"; "Shift" ; 0 ; Get(FileName) ; "HotKey" ) ]

There is also another way to set this script, but I will show you that later.

In other parameters of the HotKey.Register function, we can also specify whether FileMaker must be in front so that the key combination calls the script (local hotkey) or whether the script is executed independently (global hotkey). In addition, we can also assign a name and a tag to the hotkey for better identification. The function returns a reference to the hotkey.

In our example, we have decided to specify only the key combination (Shift+F3) in the register function, because we can also set the script with the HotKey.SetScript function. First we enter the reference of the HotKey and then the name of the database in which the script that we want to call up is located. In our case, we define the hotkey in the same solution as the script and so we can use Get(FileName). We then enter the script name. If this script requires a parameter to work, we can specify this as an optional parameter. Before we register a new hotkey, we release all old hotkeys with HotKey.UnregisterAll so that we don't have to deal with old ones. Our script looks like this.

Set Variable [ $r ; Value: MBS( "HotKey.UnregisterAll" ) ]
Set Variable [ $HotKey ; Value: MBS("HotKey.Register"; "F3"; "Shift") ]
Set Variable [ $r ; Value: MBS("HotKey.SetScript"; $HotKey; Get(FileName); "UserNotification") ]

If you are now desperately testing the key combination over and over again and it does not do what you are supposed to do, then this may be because the F keys are normally already assigned tasks. If you now also press the fn key, it works. If you do not want to press this key additionally, you can set your Mac so that you have to press the fn key if you want to use the F keys in their actual functionality, but not when you call up a key combination for FileMaker.

That concludes this door and we'll see again tomorrow for the 20th door.


Monkeybread Software Logo with Monkey with Santa hat
18 👈 19 of 24 👉 20
19 12 24 - 10:24