Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #persistent
- #Singleinstance force
- notepadKeys := new DynamicKeys((*) => WinActive("ahk_exe notepad.exe"))
- notepadKeys.RegisterHotkey(["Ctrl", "A"], Func("SendText").bind("
- (
- oHttp := ComObjCreate("WinHttp.WinHttpRequest.5.1")
- oHttp.Open("GET", )
- oHttp.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
- oHttp.send()
- )"), "Http object snippet/hold to get next help")
- notepadKeys.RegisterHotkey(["Ctrl", "B"], () => MsgBox("Help.`nThis is notepad") && MsgBox("Close it"), "Help dialog")
- ; notepadKeys.RegisterHotkey(["Ctrl", "A", "B"], () => MsgBox("Close it"), "Help dialog") ; TODO
- alwaysOnWorkKeys := new DynamicKeys((*) => true)
- alwaysOnWorkKeys.RegisterHotkey(["Alt", "F5"], Func("msgbox").bind("text"), "Just a text")
- class DynamicKeys
- {
- __New(predicate)
- {
- if !IsObject(predicate)
- MsgBox "fail"
- this.predicate := predicate
- this.keys := {}
- this.currentNode := this
- }
- RegisterHotkey(keyList, action, description := "")
- {
- node := this
- for i, key in keyList
- {
- if !keyVkCode := GetKeyVK(key)
- {
- MsgBox "Invalid key: " key
- return false
- }
- keyVkCode := Format("{:X}", keyVkCode)
- keyName := GetKeyName("vk" keyVkCode)
- if !node.keys.HasKey(keyVkCode)
- {
- node.keys.%keyVkCode% := { "name" : keyName , "keys" : {} }
- if i == 1 && this.currentNode == this
- {
- Hotkey "If", this.predicate
- Hotkey "vk" keyVkCode, ObjBindMethod(this, "private_onKeyPressed")
- Hotkey "If"
- }
- }
- node := node.keys.%keyVkCode%
- }
- node.description := description
- node.action := action
- return true
- }
- private_onKeyPressed()
- {
- keyVkCode := Format("{:X}", GetKeyVK(A_ThisHotkey))
- if !this.currentNode.keys.%keyVkCode%.HasKey("action") ; TODO: or key holded > 250 ms
- {
- this.private_disableNodeKeys(this.currentNode)
- this.currentNode := this.currentNode.keys.%keyVkCode%
- this.private_activateNodeKeys(this.currentNode)
- this.private_showNodeHelp(this.currentNode)
- }
- else
- {
- this.currentNode.keys.%keyVkCode%.action.call()
- this.private_disableNodeKeys(this.currentNode)
- this.currentNode := this
- this.private_activateNodeKeys(this.currentNode)
- }
- }
- private_disableNodeKeys(node)
- {
- Hotkey "If", this.predicate
- for key in node.keys
- Hotkey "vk" key, "Off"
- Hotkey "If"
- }
- private_activateNodeKeys(node)
- {
- Hotkey "If", this.predicate
- for key in node.keys
- {
- Hotkey "vk" key, ObjBindMethod(this, "private_onKeyPressed")
- Hotkey "vk" key, "On"
- }
- Hotkey "If"
- }
- private_showNodeHelp(node)
- {
- text := ""
- for _, v in node.keys
- text .= v.name " - " v.description "`n"
- ToolTip text
- SetTimer Func("ToolTip"), -2500
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement