diff --git a/Basic Window Switcher Hotkeys/BasicWindowSwitcherHotkeys.Session.iss b/Basic Window Switcher Hotkeys/BasicWindowSwitcherHotkeys.Session.iss new file mode 100644 index 0000000..daa22ac --- /dev/null +++ b/Basic Window Switcher Hotkeys/BasicWindowSwitcherHotkeys.Session.iss @@ -0,0 +1,170 @@ +objectdef bwshSession +{ + variable taskmanager TaskManager=${LMAC.NewTaskManager["bwshSession"]} + + variable jsonvalue SlotHotkeys="[]" + variable bool Enabled=0 + variable bool HotkeyInstalled + variable filepath AgentFolder="${Script.CurrentDirectory}" + + variable string NextWindowKey="Ctrl+Alt+X" + variable string PreviousWindowKey="Ctrl+Alt+Z" + + method Initialize() + { + LavishScript:RegisterEvent[OnHotkeyFocused] + + This:LoadSettings + This:Enable + + LGUI2.Element[consolewindow]:SetVisibility[Visible] + } + + method Shutdown() + { + ; shut down the Task Manager, ensuring that any hotkey we're still holding is effectively released + TaskManager:Destroy + + This:Disable + } + + method LoadSettings() + { + variable jsonvalue jo + + if !${jo:ParseFile["${AgentFolder~}/bwsh.Settings.json"](exists)} || !${jo.Type.Equal[object]} + { + return + } + + SlotHotkeys:SetValue["${jo.Get["slotHotkeys"].AsJSON~}"] + if ${jo.Has[nextWindowHotkey]} + NextWindowKey:Set["${jo.Get["nextWindowHotkey"]~}"] + if ${jo.Has[previousWindowHotkey]} + PreviousWindowKey:Set["${jo.Get["previousWindowHotkey"]~}"] + + if !${SlotHotkeys.Type.Equal[array]} + SlotHotkeys:SetValue["[]"] + } + + method Enable() + { + if ${Enabled} + return + + Enabled:Set[1] + This:InstallHotkeys + } + + method Disable() + { + if !${Enabled} + return + Enabled:Set[0] + This:UninstallHotkeys + } + + ; Installs a Hotkey, given a name, a key combination, and LavishScript code to execute on PRESS + method InstallHotkey(string name, string keyCombo, string methodName) + { + variable jsonvalue joBinding + ; initialize a LGUI2 input binding object with JSON + joBinding:SetValue["$$> + { + "name":${name.AsJSON~}, + "combo":${keyCombo.AsJSON~}, + "eventHandler":{ + "type":"task", + "taskManager":"bwshSession", + "task":{ + "type":"ls1.code", + "start":${methodName.AsJSON~} + } + } + } + <$$"] + + ; now add the binding to LGUI2! + LGUI2:AddBinding["${joBinding.AsJSON~}"] + } + + method InstallHotkeys() + { + variable uint i + for (i:Set[1] ; ${i}<=${SlotHotkeys.Used} ; i:Inc) + { + This:InstallHotkey[bwsh.Slot${i},"${SlotHotkeys.Get[${i}]~}","BWSHSession:OnSlotHotkey[${i}]"] + } + + if ${NextWindowKey.NotNULLOrEmpty} + This:InstallHotkey[bwsh.NextWindow,"${NextWindowKey~}","BWSHSession:NextWindow"] + if ${PreviousWindowKey.NotNULLOrEmpty} + This:InstallHotkey[bwsh.PreviousWindow,"${PreviousWindowKey~}","BWSHSession:PreviousWindow"] + } + + member:uint GetNextSlot() + { + variable uint Slot=${JMB.Slot} + if !${Slot} + return 0 + + Slot:Inc + if ${Slot}>${JMB.Slots.Used} + return 1 + + return ${Slot} + } + + member:uint GetPreviousSlot() + { + variable uint Slot=${JMB.Slot} + if !${Slot} + return 0 + + Slot:Dec + if !${Slot} + return ${JMB.Slots.Used} + + return ${Slot} + } + + method PreviousWindow() + { + variable uint previousSlot=${This.GetPreviousSlot} + if !${previousSlot} + return + + if !${Display.Window.IsForeground} + return + + uplink focus "jmb${previousSlot}" + relay "jmb${previousSlot}" "Event[OnHotkeyFocused]:Execute" + } + + method NextWindow() + { + variable uint nextSlot=${This.GetNextSlot} + if !${nextSlot} + return + + if !${Display.Window.IsForeground} + return + + uplink focus "jmb${nextSlot}" + relay "jmb${nextSlot}" "Event[OnHotkeyFocused]:Execute" + } + + method OnSlotHotkey(uint numSlot) + { + uplink focus "jmb${numSlot}" + relay "jmb${numSlot}" "Event[OnHotkeyFocused]:Execute" + } +} + +variable(global) bwshSession BWSHSession + +function main() +{ + while 1 + waitframe +} \ No newline at end of file diff --git a/Basic Window Switcher Hotkeys/BasicWindowSwitcherHotkeys.Uplink.iss b/Basic Window Switcher Hotkeys/BasicWindowSwitcherHotkeys.Uplink.iss new file mode 100644 index 0000000..98fe191 --- /dev/null +++ b/Basic Window Switcher Hotkeys/BasicWindowSwitcherHotkeys.Uplink.iss @@ -0,0 +1,110 @@ +objectdef bwshUplink +{ + variable jsonvalue SlotHotkeys="[]" + variable bool Enabled=1 + variable filepath AgentFolder="${Script.CurrentDirectory}" + variable string NextWindowKey="Ctrl+Alt+X" + variable string PreviousWindowKey="Ctrl+Alt+Z" + + method Initialize() + { + This:LoadSettings + + LGUI2:LoadPackageFile[BasicWindowSwitcherHotkeys.Uplink.lgui2Package.json] + LGUI2.Element[bwsh.filename]:SetText["${AgentFolder.Replace["/","\\"]~}\\bwsh.Settings.json"] + } + + method Shutdown() + { + This:Disable + LGUI2:UnloadPackageFile[BasicWindowSwitcherHotkeys.Uplink.lgui2Package.json] + } + + method LoadSettings() + { + variable jsonvalue jo + + if !${AgentFolder.FileExists[bwsh.Settings.json]} + { + jo:SetValue["$$> + { + "slotHotkeys":[ + "Ctrl+Alt+1", + "Ctrl+Alt+2", + "Ctrl+Alt+3", + "Ctrl+Alt+4", + "Ctrl+Alt+5", + "Ctrl+Alt+6", + "Ctrl+Alt+7", + "Ctrl+Alt+8", + "Ctrl+Alt+9", + "Ctrl+Alt+0", + "Ctrl+Alt+-", + "Ctrl+Alt+=", + ], + "previousWindowHotkey":"Ctrl+Alt+Z", + "nextWindowHotkey":"Ctrl+Alt+X" + } + <$$"] + + jo:WriteFile["${AgentFolder~}/bwsh.Settings.json",multiline] + } + + if !${jo:ParseFile["${AgentFolder~}/bwsh.Settings.json"](exists)} || !${jo.Type.Equal[object]} + { + return + } + + SlotHotkeys:SetValue["${jo.Get["slotHotkeys"].AsJSON~}"] + if ${jo.Has[nextWindowHotkey]} + NextWindowKey:Set["${jo.Get["nextWindowHotkey"]~}"] + if ${jo.Has[previousWindowHotkey]} + PreviousWindowKey:Set["${jo.Get["previousWindowHotkey"]~}"] + + if !${SlotHotkeys.Type.Equal[array]} + SlotHotkeys:SetValue["[]"] + } + + method StoreSettings() + { + variable jsonvalue jo + jo:SetValue["${This.AsJSON~}"] + jo:WriteFile["${AgentFolder~}/bwsh.Settings.json",multiline] + } + + member AsJSON() + { + variable jsonvalue jo="{}" + jo:Set["slotHotkeys","${SlotHotkeys.AsJSON~}"] + jo:Set["nextWindowHotkey","${NextWindowKey.AsJSON~}"] + jo:Set["previousWindowHotkey","${PreviousWindowKey.AsJSON~}"] + return "${jo.AsJSON~}" + } + + method Enable() + { + if ${Enabled} + return + + Enabled:Set[1] + + relay all BWSHSession:InstallHotkey + } + + method Disable() + { + if !${Enabled} + return + Enabled:Set[0] + relay all BWSHSession:UninstallHotkey + } + +} + +variable(global) bwshUplink BWSHUplink + +function main() +{ + while 1 + waitframe +} \ No newline at end of file diff --git a/Basic Window Switcher Hotkeys/BasicWindowSwitcherHotkeys.Uplink.lgui2Package.json b/Basic Window Switcher Hotkeys/BasicWindowSwitcherHotkeys.Uplink.lgui2Package.json new file mode 100644 index 0000000..6a68216 --- /dev/null +++ b/Basic Window Switcher Hotkeys/BasicWindowSwitcherHotkeys.Uplink.lgui2Package.json @@ -0,0 +1,102 @@ +{ + "$schema": "http://www.lavishsoft.com/schema/lgui2Package.json", + "templates":{ + "bwsh.defaultSettings":{ + "slotHotkeys":[ + "Ctrl+Alt+1", + "Ctrl+Alt+2", + "Ctrl+Alt+3", + "Ctrl+Alt+4", + "Ctrl+Alt+5", + "Ctrl+Alt+6", + "Ctrl+Alt+7", + "Ctrl+Alt+8", + "Ctrl+Alt+9", + "Ctrl+Alt+0", + "Ctrl+Alt+-", + "Ctrl+Alt+=" + ], + "previousWindowHotkey":"Ctrl+Alt+Z", + "nextWindowHotkey":"Ctrl+Alt+X" + } + }, + "elements": [ + { + "type": "window", + "name": "basicWindowSwitcherHotkeys.window", + "title": "Basic Window Switcher Hotkeys", + "visibility":"hidden", + "content":{ + "type":"stackpanel", + "orientation":"vertical", + "backgroundBrush":{ + "color":"#FF003322" + }, + "padding":20, + "children":[ + { + "type":"textblock", + "text":"Joe Multiboxer: Basic Window Switcher Hotkeys", + "margin":5, + "font":{ + "bold":true, + "face":"Verdana", + "heightFactor":1.5 + } + }, + { + "type":"textblock", + "text":"Work is in progress on this Agent's configuration GUI.", + "margin":[5,5,5,0] + }, + { + "type":"textblock", + "text":"Default Hotkeys: Ctrl+Alt+1 through Ctrl+Alt+=", + "margin":[5,15,5,10], + "font":{ + "heightFactor":1.5, + "bold":true + } + }, + { + "type":"textblock", + "text":"Hotkeys can be set in the file:", + "margin":[5,5,5,0] + }, + { + "type":"textblock", + "name":"bwsh.filename", + "margin":[5,5,5,10], + "font":{ + "heightFactor":1.2, + "bold":true + } + }, + { + "type":"expander", + "margin":5, + "header":"More ...", + "expanded":false, + "content":{ + "type":"stackpanel", + "orientation":"vertical", + "children":[ + { + "type":"button", + "content":"Reload Basic Window Switcher Hotkeys", + "margin":[5,5,5,0], + "eventHandlers":{ + "onPress":{ + "type":"code", + "code":"JMB.Agent[Basic Window Switcher Hotkeys]:Stop:Start" + } + } + } + ] + } + } + ] + } + } + ] +} \ No newline at end of file diff --git a/Basic Window Switcher Hotkeys/agent.json b/Basic Window Switcher Hotkeys/agent.json new file mode 100644 index 0000000..4c630b2 --- /dev/null +++ b/Basic Window Switcher Hotkeys/agent.json @@ -0,0 +1,34 @@ +{ + "$schema": "http://www.lavishsoft.com/schema/agent.json", + "name": "Basic Window Switcher Hotkeys", + "platforms": { + "joe multiboxer uplink": { + "eventHandlers": { + "onAgentStartup": { + "code": [ + "run BasicWindowSwitcherHotkeys.Uplink.iss" + ] + }, + "onAgentShutdown": { + "code": [ + "endscript BasicWindowSwitcherHotkeys.Uplink" + ] + } + } + }, + "joe multiboxer session": { + "eventHandlers": { + "onAgentStartup": { + "code": [ + "run BasicWindowSwitcherHotkeys.Session.iss" + ] + }, + "onAgentShutdown": { + "code": [ + "endscript BasicWindowSwitcherHotkeys.Session" + ] + } + } + } + } +} \ No newline at end of file