Script: Hotkey Manager
Game: X3: Terran Conflict 1.3+
- This is a library script to make it easier to register and maintain hotkeys.
The advantage of using this, is that the hotkeys will be saved in memory so can easily be found later
and they can automatically be removed if the script is no longer available.
So scripts dont need to create extra uninstall routines for removing the hotkeys
- Using it is fairly straight forward, you simply need to call the add script withint your setup script
The first argument, nameid, is a unique string identifier for your hotkey. If your scripts uses multiple hotkeys, they need to have seperate idsCode:= call script 'plugin.hotkeymanager.add' nameid='myhotkey' Display Text='My Hotkey' Hotkey Script='plugin.myscript.hotkey'
The next argument, Display Text, is the text that is display in the controls menu.
The last argument, Hotkey Script, the string name of the script to run when the hotkey is pressed.
This is all you need to do, theres no need to remove the hotkey, the manager will take care of this.
However, unlike with normal hotkeys, you have to register this each time the game loads, ie, in your setup script, you dont need any check, just call the script each time.
Also, it must not be in an Init script
- The add script will always returns true, this means you can use it to detect if the hotkey manager is installed.
This will allow you to create a script that can still work without the library, ie
This will then use your own hotkey control if the manager is not installed.Code:if not [THIS] -> call script 'plugin.hotkeymanager.add' $key = register hotkey $text.... end
- Now, how the manager actually works.
The manager maintains a list of all registered hotkeys and thier setings in a global varible.
There is in init script that is run before all the script setups, this script will go through the whole list and mark all the hotkeys to be deleted
When the setup scripts are run and they add thier hotkeys, if the hotkey exists, they will be marked not to be deleted.
The manager then has its own setup script that will run another script that waits for a short time. After this time, it will check all the hotkeys that are still marked as deleted and remove them.
So any hotkey that hasn't been readded in setup scripts, ie because the setup script no longer exists, will then be removed.