Advertisement
Guest User

PressedKeys - ShowAndHide & EnableAndDisable

a guest
Dec 28th, 2012
1,603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Pressed keys by Michał Durak (micechal) based on Jon's On-Screen keyboard.
  2. ;
  3. ;Changelog:
  4. ;v1.0 - Initial release
  5.  
  6.  
  7.  
  8.  
  9. ;---- Configuration Section: Customize the size of the on-screen keyboard and
  10. ; other options here.
  11.  
  12. ; Changing this font size will make the entire on-screen keyboard get
  13. ; larger or smaller:
  14. k_FontSize = 10
  15. k_FontName = Verdana  ; This can be blank to use the system's default font.
  16. k_FontStyle = Bold    ; Example of an alternative: Italic Underline
  17.  
  18. ; Names for the tray menu items:
  19. k_MenuItemHideArrows = Hide arrow keys
  20. k_MenuItemShowArrows = Show arrow keys
  21. k_MenuItemHideShift = Hide shift
  22. k_MenuItemShowShift = Show shift
  23. k_MenuItemHideSpacebar = Hide spacebar
  24. k_MenuItemShowSpacebar = Show spacebar
  25. k_MenuItemHideAll = Hide all
  26. k_MenuItemShowAll = Show all
  27.  
  28. ; To have the keyboard appear on a monitor other than the primary, specify
  29. ; a number such as 2 for the following variable.  Leave it blank to use
  30. ; the primary:
  31. k_Monitor =
  32.  
  33. ; Background color (default is green (00FF00) for Chroma Keying in OBS)
  34. Background_color = 00FF00
  35.  
  36. ; How do you want to see pressed keys:
  37. ; Show/Hide will hide all buttons at start and then make them visible when keys are pressed on keyboard
  38. ; Enable/Disable will gray out all buttons at start and then make them normal when keys are pressed on keyboard
  39.  
  40. EnableAndDisable = n      ;Only two options here, y - yes (will use Enable/Disable), anything else - will use Show/Hide
  41.  
  42.  
  43.  
  44. ;---- End of configuration section.  Don't change anything below this point
  45. ; unless you want to alter the basic nature of the script.
  46.  
  47. if EnableAndDisable = y
  48. {
  49. ShowOrEnable = Enable
  50. HideOrDisable = Disable
  51. }
  52. else
  53. {
  54. ShowOrEnable = Show
  55. HideOrDisable = Hide
  56. }
  57.  
  58.  
  59. ;---- Alter the tray icon menu:
  60. Menu, Tray, Add, %k_MenuItemShowAll%, k_ShowAll
  61. Menu, Tray, Add, %k_MenuItemHideAll%, k_HideAll
  62. Menu, Tray, Add, %k_MenuItemHideArrows%, k_ShowHideArrows
  63. Menu, Tray, Add, %k_MenuItemHideShift%, k_ShowHideShift
  64. Menu, Tray, Add, %k_MenuItemHideSpacebar%, k_ShowHideSpacebar
  65. Menu, Tray, Add, &Exit, k_MenuExit
  66. Menu, Tray, NoStandard
  67.  
  68. ;---- Calculate object dimensions based on chosen font size:
  69. k_KeyWidth = %k_FontSize%
  70. k_KeyWidth *= 3
  71. k_KeyHeight = %k_FontSize%
  72. k_KeyHeight *= 3
  73. k_KeyMargin = %k_FontSize%
  74. k_KeyMargin /= 6
  75. k_SpacebarWidth = %k_FontSize%
  76. k_SpacebarWidth *= 25
  77. k_KeyWidthHalf = %k_KeyWidth%
  78. k_KeyWidthHalf /= 2
  79.  
  80. k_KeySize = w%k_KeyWidth% h%k_KeyHeight%
  81. k_Position = x+%k_KeyMargin% %k_KeySize%
  82.  
  83. ;---- Create a GUI window for the on-screen keyboard:
  84. Gui, +ToolWindow
  85. Gui, 2:+ToolWindow
  86. Gui, 3:+ToolWindow
  87. Gui, Font, s%k_FontSize% %k_FontStyle%, %k_FontName%
  88. Gui, 2:Font, s%k_FontSize% %k_FontStyle%, %k_FontName%
  89. Gui, 3:Font, s%k_FontSize% %k_FontStyle%, %k_FontName%
  90. Gui, Color, %Background_color%
  91. Gui, 2:Color, %Background_color%
  92. Gui, 3:Color, %Background_color%
  93.  
  94. ;---- Add a button for each key. Position the first button with absolute
  95. ; coordinates so that all other buttons can be positioned relative to it:
  96.  
  97. ;ARROWS
  98.  
  99. Gui, Add, Button, section %k_KeySize% xm+%k_KeyWidth%,
  100. Gui, Add, Button, xm y+%k_KeyMargin% h%k_KeyHeight%,; Auto-width.
  101. Gui, Add, Button, %k_Position%,
  102. Gui, Add, Button, %k_Position%,
  103.  
  104. ;SHIFT
  105.  
  106. Gui, 2:Add, Button, xm y+%k_KeyMargin% h%k_KeyHeight%, Shift%A_Space%%A_Space%
  107.  
  108. ;SPACEBAR
  109.  
  110. Gui, 3:Add, Button, h%k_KeyHeight% x+%k_KeyMargin% w%k_SpacebarWidth%, Space
  111.  
  112. ;---- Show the window:
  113. Gui, Show
  114. WinWait, %A_ScriptName%
  115. WinSetTitle, Arrows
  116. Control, %HideOrDisable%, ,, Arrows
  117. Control, %HideOrDisable%, ,, Arrows
  118. Control, %HideOrDisable%, ,, Arrows
  119. Control, %HideOrDisable%, ,, Arrows
  120. Gui, 2:Show
  121. WinWait, %A_ScriptName%
  122. WinSetTitle, Shift
  123. Control, %HideOrDisable%, , Shift, Shift
  124. Gui, 3:Show
  125. WinWait, %A_ScriptName%
  126. WinSetTitle, Spacebar
  127. Control, %HideOrDisable%, , Space, Spacebar
  128. k_IsVisibleAll = y
  129. k_IsVisibleArrows = y
  130. k_IsVisibleShift = y
  131. k_IsVisibleSpacebar = y
  132.  
  133. ;WinGet, k_ID, ID, A   ; Get its window ID.
  134. ;WinGetPos,,, k_WindowWidth, k_WindowHeight, A
  135.  
  136. ;---- When a key is pressed by the user, click the corresponding button on-screen:
  137.  
  138.  
  139. ;ARROWS
  140.  
  141. ~*Up::
  142. Control, %ShowOrEnable%, ,, Arrows
  143. KeyWait, Up
  144. Control, %HideOrDisable%, ,, Arrows
  145. return
  146.  
  147. ~*Down::
  148. Control, %ShowOrEnable%, ,, Arrows
  149. KeyWait, Down
  150. Control, %HideOrDisable%, ,, Arrows
  151. return
  152.  
  153. ~*Left::
  154. Control, %ShowOrEnable%, ,, Arrows
  155. KeyWait, Left
  156. Control, %HideOrDisable%, ,, Arrows
  157. return
  158.  
  159. ~*Right::
  160. Control, %ShowOrEnable%, ,, Arrows
  161. KeyWait, Right
  162. Control, %HideOrDisable%, ,, Arrows
  163. return
  164.  
  165.  
  166. ;SHIFT
  167.  
  168. ~*Shift::
  169. Control, %ShowOrEnable%, , Shift, Shift
  170. KeyWait, Shift
  171. Control, %HideOrDisable%, , Shift, Shift
  172. return
  173.  
  174.  
  175. ;SPACEBAR
  176.  
  177. ~*Space::
  178. Control, %ShowOrEnable%, , Space, Spacebar
  179. KeyWait, Space
  180. Control, %HideOrDisable%, , Space, Spacebar
  181. return
  182.  
  183.  
  184. ; ---- Tray Menu ----
  185.  
  186. ;HIDE ALL
  187.  
  188. k_HideAll:
  189. Gui, Cancel
  190. Gui, 2:Cancel
  191. Gui, 3:Cancel
  192. if k_IsVisibleArrows = y
  193. {
  194. Menu, Tray, Rename, %k_MenuItemHideArrows%, %k_MenuItemShowArrows%
  195. k_IsVisibleArrows = n
  196. }
  197. if k_IsVisibleShift = y
  198. {
  199. Menu, Tray, Rename, %k_MenuItemHideShift%, %k_MenuItemShowShift%
  200. k_IsVisibleShift = n
  201. }
  202. if k_IsVisibleSpacebar = y
  203. {
  204. Menu, Tray, Rename, %k_MenuItemHideSpacebar%, %k_MenuItemShowSpacebar%
  205. k_IsVisibleSpacebar = n
  206. }
  207. k_IsVisibleAll = n
  208. return
  209.  
  210. ;SHOW ALL
  211.  
  212. k_ShowAll:
  213. if k_IsVisibleAll = n
  214.   {
  215.     if k_IsVisibleArrows = n
  216.     {
  217.     Gui, Show
  218.     Menu, Tray, Rename, %k_MenuItemShowArrows%, %k_MenuItemHideArrows%
  219.     k_IsVisibleArrows = y
  220.     }
  221.     if k_IsVisibleShift = n
  222.     {
  223.     Menu, Tray, Rename, %k_MenuItemShowShift%, %k_MenuItemHideShift%
  224.     k_IsVisibleShift = y
  225.     Gui, 2:Show
  226.     }
  227.     if k_IsVisibleSpacebar = n
  228.     {
  229.     Menu, Tray, Rename, %k_MenuItemShowSpacebar%, %k_MenuItemHideSpacebar%
  230.     k_IsVisibleSpacebar = y
  231.     Gui, 3:Show
  232.     }
  233.     k_IsVisibleAll = y
  234.     }
  235. return
  236.  
  237. ;ARROWS
  238.  
  239. k_ShowHideArrows:
  240. if k_IsVisibleArrows = y
  241. {
  242.     Gui, Cancel
  243.     Menu, Tray, Rename, %k_MenuItemHideArrows%, %k_MenuItemShowArrows%
  244.     k_IsVisibleArrows = n
  245.     k_IsVisibleAll = n
  246. }
  247. else
  248. {
  249.     Gui, Show
  250.     Menu, Tray, Rename, %k_MenuItemShowArrows%, %k_MenuItemHideArrows%
  251.     k_IsVisibleArrows = y
  252. }
  253. return
  254.  
  255. ;SHIFT
  256.  
  257. k_ShowHideShift:
  258. if k_IsVisibleShift = y
  259. {
  260.     Gui, 2:Cancel
  261.     Menu, Tray, Rename, %k_MenuItemHideShift%, %k_MenuItemShowShift%
  262.     k_IsVisibleShift = n
  263.     k_IsVisibleAll = n
  264. }
  265. else
  266. {
  267.     Gui, 2:Show
  268.     Menu, Tray, Rename, %k_MenuItemShowShift%, %k_MenuItemHideShift%
  269.     k_IsVisibleShift = y
  270. }
  271. return
  272.  
  273. ;SPACEBAR
  274.  
  275. k_ShowHideSpacebar:
  276. if k_IsVisibleSpacebar = y
  277. {
  278.     Gui, 3:Cancel
  279.     Menu, Tray, Rename, %k_MenuItemHideSpacebar%, %k_MenuItemShowSpacebar%
  280.     k_IsVisibleSpacebar = n
  281.     k_IsVisibleAll = n
  282. }
  283. else
  284. {
  285.     Gui, 3:Show
  286.     Menu, Tray, Rename, %k_MenuItemShowSpacebar%, %k_MenuItemHideSpacebar%
  287.     k_IsVisibleSpacebar = y
  288. }
  289. return
  290.  
  291. GuiClose:
  292. k_MenuExit:
  293. ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement