Advertisement
mece

WindowSwitcher

Jul 24th, 2022 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.94 KB | None | 0 0
  1. -- 【 LICENCE 】
  2. --------------------------------------------------------------------------------
  3. -- The MIT License (MIT)
  4. --
  5. -- Copyright (c) mece from opencheattables.org
  6. --
  7. -- Permission is hereby granted, free of charge, to any person obtaining a
  8. -- copy of this software and associated documentation files (the "Software"),
  9. -- to deal in the Software without restriction, including without limitation
  10. -- the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. -- and/or sell copies of the Software, and to permit persons to whom the
  12. -- Software is furnished to do so, subject to the following conditions:
  13. --
  14. -- The above copyright notice and this permission notice shall be included in
  15. -- all copies or substantial portions of the Software.
  16. --
  17. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. -- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. -- DEALINGS IN THE SOFTWARE.
  24. --------------------------------------------------------------------------------
  25. -- 【 FILE INFO 】
  26. --  ㅤ❖ This is an extention for Cheat Engine 7.4 (https://cheatengine.org)
  27. --
  28. -- 【 FEATURES 】
  29. --  ㅤ❖ Press Ctrl+Tab once to switch between the last two focused CE windows
  30. --  ㅤ❖ Press Ctrl+Tab multiple times switch to the selected window from the list
  31. --  ㅤ❖ Release Ctrl to hide the window list
  32. --  ㅤ❖ While Ctrl is down the window list is visible
  33. --  ㅤㅤ Use Up and Down arrow keys or mouse left clicks to switch windows
  34. --  ㅤ❖ Press Delete to close selected window (except the main one)
  35. --  ㅤ❖ Switch minimized window to temporary restore it
  36. --  ㅤㅤ Release Ctrl to keep window restored
  37. --
  38. -- 【 HOW TO INSTALL 】
  39. --  ㅤ❖ Place the .lua file in CE autorun folder. Could be:
  40. --  ㅤㅤ C:\Program Files\Cheat Engine 7.4\autorun
  41. --  ㅤ❖ Place the .frm file in CE autorun\forms folder. Could be:
  42. --  ㅤㅤ C:\Program Files\Cheat Engine 7.4\autorun\forms
  43. --
  44. -- 【 CHANGE LOG 】
  45. --  ㅤ⋯ 2022-06-03 ⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
  46. --  ㅤ❖ initial version
  47. --
  48. -- 【 CONTACT THE AUTHOR 】
  49. --  ㅤ❖ https://opencheattables.org/viewforum.php?f=14
  50. --  ㅤ❖ https://forum.cheatengine.org/viewforum.php?f=130
  51. --
  52. --------------------------------------------------------------------------------
  53. local wsw = {}
  54. local pathsep = getOperatingSystem() and [[\]] or [[/]]
  55. local forms_path = getAutoRunPath()..'forms'..pathsep
  56. wsw.maximized_form = nil
  57. --------------------------------------------------------------------------------
  58. local function show_switcher()
  59.   if wsw.tab_hotkey_enabled and getCheatEngineProcessID() == getForegroundProcess() then
  60.     wsw.tab_hotkey_enabled = false
  61.     local lb = CEFormWindowSwitcher.CEListBoxWindows
  62.     lb.Items.beginUpdate()
  63.     lb.Items.clear()
  64.     for i=0,getFormCount()-1 do
  65.       local form = getForm(i)
  66.       if form.Visible and form ~= CEFormWindowSwitcher then
  67.         lb.Items.add(form.Caption, userDataToInteger(form))
  68.       end
  69.     end
  70.     wsw.maximized_form = nil
  71.     lb.Items.endUpdate()
  72.     CEFormWindowSwitcher.show()
  73.     lb.ItemIndex = lb.Items.Count > 1 and 1 or 0
  74.   end
  75. end
  76. --------------------------------------------------------------------------------
  77. function CEFormWindowSwitcher_CEListBoxWindows_OnSelectionChange(sender, user)
  78.   if wsw.maximized_form then
  79.     wsw.maximized_form.WindowState = 'wsMinimized'
  80.     wsw.maximized_form = nil
  81.   end
  82.   local form = integerToUserData(sender.Items.Data[sender.ItemIndex])
  83.   if form.WindowState == 'wsMinimized' then
  84.     form.WindowState = 'wsNormal'
  85.     wsw.maximized_form = form
  86.   end
  87.   form.bringToFront()
  88.   sender.setFocus()
  89. end
  90. --------------------------------------------------------------------------------
  91. function CEFormWindowSwitcher_CEListBoxWindows_OnKeyDown(sender, key)
  92.   local list = sender.Items
  93.   local start = sender.ItemIndex
  94.   if key == VK_TAB then
  95.     sender.ItemIndex = start < list.Count-1 and start + 1 or 0
  96.   end
  97.   if key == VK_DELETE then
  98.     local form = integerToUserData(list.Data[sender.ItemIndex])
  99.     if form ~= MainForm then
  100.       form.Close()
  101.       local selected = sender.ItemIndex
  102.       list.delete(selected)
  103.       sender.ItemIndex = selected > 1 and selected-1 or 0
  104.     end
  105.   end
  106.   return key
  107. end
  108. --------------------------------------------------------------------------------
  109. local function control_modifier()
  110.   if wsw.control_hotkey_enabled then
  111.     wsw.control_hotkey_enabled = false
  112.     wsw.tab_hotkey_enabled = true
  113.     wsw.waitTab = createTimer(MainForm)
  114.     wsw.waitTab.Interval = 200
  115.     wsw.waitTab.OnTimer = function(thisTimer)
  116.       if not isKeyPressed(VK_CONTROL) then
  117.         CEFormWindowSwitcher.close()
  118.         wsw.tab_hotkey_enabled = false
  119.         wsw.control_hotkey_enabled = true
  120.         thisTimer.destroy()
  121.       end
  122.     end
  123.   end
  124. end
  125. --------------------------------------------------------------------------------
  126. function file_exists(file_path)
  127.    local f = io.open(file_path, "r")
  128.    return f ~= nil and io.close(f)
  129. end
  130. --------------------------------------------------------------------------------
  131. local CEFormWindowSwitcher = nil
  132. local file_path = forms_path .. 'WindowSwitcher.FRM'
  133. if file_exists(file_path) then
  134.   CEFormWindowSwitcher = createFormFromFile(file_path)
  135.   wsw.control_hotkey = createHotkey(control_modifier, VK_CONTROL)
  136.   wsw.control_hotkey_enabled = true
  137.   wsw.tab_hotkey = createHotkey(show_switcher, VK_TAB)
  138.   wsw.tab_hotkey_enabled = false
  139. else
  140.   print("WindowSwitcher.FRM not found!")
  141. end
  142. --------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement