DesktopX: Hotkeys (intermediate)
From WinCustomize Wiki
| Hotkeys | ||||||||
| ||||||||
Contents |
[edit] Object.RegisterHotkey
The documentation for hotkey creation in DesktopX seemed a little confusing.
The following wiki will show an example of the Object.RegisterHotkey in use and also how to make a quick tool to return values which the Object.RegisterHotkey command will accept.
[edit] Command description
Object.RegisterHotkey and Object.UnregisterHotkey let you register/unregister a hotkey combination.
A special event is called when the user hits the hotkey.
- Note - I have found you can only use the Object.RegisterHotkey command in the Object_OnScriptEnter function otherwise it won't register the hotkey. Please correct if this is wrong.
[edit] Example usage:
'Registers Shift+8 as a hotkey. 'The number 1 is the hotkey reference number. 'The string "312" is the reference code for Shift+8 key combination Sub Object_OnScriptEnter 'register the hotkey Object.RegisterHotkey 1, "312" End Sub
Sub Object_OnHotkey(id)
'respond to hotkey being pressed
If id = 1 then
msgbox("hotkey pressed")
End If
End Sub
hotkeyValue appears to accept string values for 'hotkeyValue'.
[edit] How to get the string value to use for a specific hotkey:
Experimentation gave this method to get a working hotkey reference.
This should not be necessary if someone would like to update with clear instruction for beginners on what values the Object.RegisterHotkey command takes.
Step 1. Create a desktopx object.
Step 2. Make it a TEXT OBJECT and give it a name
Step 3. Create a script function in the object as follows
Function Object_OnLButtonUp(x,y,dragged)
If dragged = True then Exit Function
Set frm = DesktopX.CreateForm
frm.AddPreference "HotkeySelector"
frm.Preference("HotkeySelector").Type = "Hotkey"
frm.Preference("HotkeySelector").DefaultValue = ""
frm.Preference("HotkeySelector").Caption = "Press a hotkey combination"
frm.Preference("HotkeySelector").Description = ""
frm.Prompt
hotkey_string = frm.Preference("HotkeySelector").Value
Object.Text = hotkey_string
System.Clipboard = hotkey_string
MsgBox("The string for this hotkey is " & hotkey_string & Chr(13) & _
"Remember, hotkeys should be registered in the OnScriptEnter function")
End Function
To use the object click it. You will be able to enter in a key combination as a hotkey.
A message will then appear telling you the relevant hotkey string.
You can replace "312" in the example at the top of this tutorial with this value to make your own hotkeys.
It will also copy the value into the system clipboard for quick pasting into a script.
