PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/AutoHotkey.docset/Contents/Resources/Documents/scripts/KeyboardOnScreen.htm

https://gitlab.com/ahkscript/Autohotkey.docset
HTML | 246 lines | 207 code | 39 blank | 0 comment | 0 complexity | 5276c59bdf0478aae6389938b70dd553 MD5 | raw file
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>On-Screen Keyboard (requires XP/2k/NT) -- by Jon</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <link href="../static/theme.css" rel="stylesheet" type="text/css" />
  8. <script src="../static/content.js" type="text/javascript"></script>
  9. </head>
  10. <body>
  11. <h1>On-Screen Keyboard (requires XP/2k/NT) -- by Jon</h1>
  12. <p>This script creates a mock keyboard at the bottom of your screen that shows
  13. the keys you are pressing in real time. I made it to help me to learn to
  14. touch-type (to get used to not looking at the keyboard). The size of the
  15. on-screen keyboard can be customized at the top of the script. Also, you
  16. can double-click the tray icon to show or hide the keyboard.
  17. </p>
  18. <p><a href="KeyboardOnScreen.ahk">Download This Script</a> &nbsp;| &nbsp;<a href="index.htm">Other Sample Scripts</a> &nbsp;| &nbsp;<a href="../AutoHotkey.htm">Home</a></p>
  19. <pre class="NoIndent"><em>;---- Configuration Section: Customize the size of the on-screen keyboard and
  20. ; other options here.</em>
  21. <em>; Changing this font size will make the entire on-screen keyboard get
  22. ; larger or smaller:</em>
  23. k_FontSize = 10
  24. k_FontName = Verdana <em>; This can be blank to use the system's default font.</em>
  25. k_FontStyle = Bold <em>; Example of an alternative: Italic Underline</em>
  26. <em>; Names for the tray menu items:</em>
  27. k_MenuItemHide = Hide on-screen &amp;keyboard
  28. k_MenuItemShow = Show on-screen &amp;keyboard
  29. <em>; To have the keyboard appear on a monitor other than the primary, specify
  30. ; a number such as 2 for the following variable. Leave it blank to use
  31. ; the primary:</em>
  32. k_Monitor =
  33. <em>;---- End of configuration section. Don't change anything below this point
  34. ; unless you want to alter the basic nature of the script.</em>
  35. <em>;---- Alter the tray icon menu:</em>
  36. Menu, Tray, Add, %k_MenuItemHide%, k_ShowHide
  37. Menu, Tray, Add, &amp;Exit, k_MenuExit
  38. Menu, Tray, Default, %k_MenuItemHide%
  39. Menu, Tray, NoStandard
  40. <em>;---- Calculate object dimensions based on chosen font size:</em>
  41. k_KeyWidth = %k_FontSize%
  42. k_KeyWidth *= 3
  43. k_KeyHeight = %k_FontSize%
  44. k_KeyHeight *= 3
  45. k_KeyMargin = %k_FontSize%
  46. k_KeyMargin /= 6
  47. k_SpacebarWidth = %k_FontSize%
  48. k_SpacebarWidth *= 25
  49. k_KeyWidthHalf = %k_KeyWidth%
  50. k_KeyWidthHalf /= 2
  51. k_KeySize = w%k_KeyWidth% h%k_KeyHeight%
  52. k_Position = x+%k_KeyMargin% %k_KeySize%
  53. <em>;---- Create a GUI window for the on-screen keyboard:</em>
  54. Gui, Font, s%k_FontSize% %k_FontStyle%, %k_FontName%
  55. Gui, -Caption +E0x200 +ToolWindow
  56. TransColor = F1ECED
  57. Gui, Color, %TransColor% <em>; This color will be made transparent later below.</em>
  58. <em>;---- Add a button for each key. Position the first button with absolute
  59. ; coordinates so that all other buttons can be positioned relative to it:</em>
  60. Gui, Add, Button, section %k_KeySize% xm+%k_KeyWidth%, 1
  61. Gui, Add, Button, %k_Position%, 2
  62. Gui, Add, Button, %k_Position%, 3
  63. Gui, Add, Button, %k_Position%, 4
  64. Gui, Add, Button, %k_Position%, 5
  65. Gui, Add, Button, %k_Position%, 6
  66. Gui, Add, Button, %k_Position%, 7
  67. Gui, Add, Button, %k_Position%, 8
  68. Gui, Add, Button, %k_Position%, 9
  69. Gui, Add, Button, %k_Position%, 0
  70. Gui, Add, Button, %k_Position%, -
  71. Gui, Add, Button, %k_Position%, =
  72. Gui, Add, Button, %k_Position%, Bk
  73. Gui, Add, Button, xm y+%k_KeyMargin% h%k_KeyHeight%, Tab <em>; Auto-width.</em>
  74. Gui, Add, Button, %k_Position%, Q
  75. Gui, Add, Button, %k_Position%, W
  76. Gui, Add, Button, %k_Position%, E
  77. Gui, Add, Button, %k_Position%, R
  78. Gui, Add, Button, %k_Position%, T
  79. Gui, Add, Button, %k_Position%, Y
  80. Gui, Add, Button, %k_Position%, U
  81. Gui, Add, Button, %k_Position%, I
  82. Gui, Add, Button, %k_Position%, O
  83. Gui, Add, Button, %k_Position%, P
  84. Gui, Add, Button, %k_Position%, [
  85. Gui, Add, Button, %k_Position%, ]
  86. Gui, Add, Button, %k_Position%, \
  87. Gui, Add, Button, xs+%k_KeyWidthHalf% y+%k_KeyMargin% %k_KeySize%, A
  88. Gui, Add, Button, %k_Position%, S
  89. Gui, Add, Button, %k_Position%, D
  90. Gui, Add, Button, %k_Position%, F
  91. Gui, Add, Button, %k_Position%, G
  92. Gui, Add, Button, %k_Position%, H
  93. Gui, Add, Button, %k_Position%, J
  94. Gui, Add, Button, %k_Position%, K
  95. Gui, Add, Button, %k_Position%, L
  96. Gui, Add, Button, %k_Position%, `;
  97. Gui, Add, Button, %k_Position%, '
  98. Gui, Add, Button, x+%k_KeyMargin% h%k_KeyHeight%, Enter <em>; Auto-width.</em>
  99. <em>; The first button below adds %A_Space% at the end to widen it a little,
  100. ; making the layout of keys next to it more accurately reflect a real keyboard:</em>
  101. Gui, Add, Button, xm y+%k_KeyMargin% h%k_KeyHeight%, Shift%A_Space%%A_Space%
  102. Gui, Add, Button, %k_Position%, Z
  103. Gui, Add, Button, %k_Position%, X
  104. Gui, Add, Button, %k_Position%, C
  105. Gui, Add, Button, %k_Position%, V
  106. Gui, Add, Button, %k_Position%, B
  107. Gui, Add, Button, %k_Position%, N
  108. Gui, Add, Button, %k_Position%, M
  109. Gui, Add, Button, %k_Position%, `,
  110. Gui, Add, Button, %k_Position%, .
  111. Gui, Add, Button, %k_Position%, /
  112. Gui, Add, Button, xm y+%k_KeyMargin% h%k_KeyHeight%, Ctrl <em>; Auto-width.</em>
  113. Gui, Add, Button, h%k_KeyHeight% x+%k_KeyMargin%, Win <em>; Auto-width.</em>
  114. Gui, Add, Button, h%k_KeyHeight% x+%k_KeyMargin%, Alt <em>; Auto-width.</em>
  115. Gui, Add, Button, h%k_KeyHeight% x+%k_KeyMargin% w%k_SpacebarWidth%, Space
  116. <em>;---- Show the window:</em>
  117. Gui, Show
  118. k_IsVisible = y
  119. WinGet, k_ID, ID, A <em>; Get its window ID.</em>
  120. WinGetPos,,, k_WindowWidth, k_WindowHeight, A
  121. <em>;---- Position the keyboard at the bottom of the screen (taking into account
  122. ; the position of the taskbar):</em>
  123. SysGet, k_WorkArea, MonitorWorkArea, %k_Monitor%
  124. <em>; Calculate window's X-position:</em>
  125. k_WindowX = %k_WorkAreaRight%
  126. k_WindowX -= %k_WorkAreaLeft% <em>; Now k_WindowX contains the width of this monitor.</em>
  127. k_WindowX -= %k_WindowWidth%
  128. k_WindowX /= 2 <em>; Calculate position to center it horizontally.
  129. ; The following is done in case the window will be on a non-primary monitor
  130. ; or if the taskbar is anchored on the left side of the screen:</em>
  131. k_WindowX += %k_WorkAreaLeft%
  132. <em>; Calculate window's Y-position:</em>
  133. k_WindowY = %k_WorkAreaBottom%
  134. k_WindowY -= %k_WindowHeight%
  135. WinMove, A,, %k_WindowX%, %k_WindowY%
  136. WinSet, AlwaysOnTop, On, ahk_id %k_ID%
  137. WinSet, TransColor, %TransColor% 220, ahk_id %k_ID%
  138. <em>;---- Set all keys as hotkeys. See www.asciitable.com</em>
  139. k_n = 1
  140. k_ASCII = 45
  141. Loop
  142. {
  143. Transform, k_char, Chr, %k_ASCII%
  144. StringUpper, k_char, k_char
  145. if k_char not in &lt;,&gt;,^,~,&#129;,`,
  146. Hotkey, ~*%k_char%, k_KeyPress
  147. <em>; In the above, the asterisk prefix allows the key to be detected regardless</em>
  148. <em>; of whether the user is holding down modifier keys such as Control and Shift.</em>
  149. if k_ASCII = 93
  150. break
  151. k_ASCII++
  152. }
  153. return <em>; End of auto-execute section.</em>
  154. <em>;---- When a key is pressed by the user, click the corresponding button on-screen:</em>
  155. ~*Backspace::
  156. ControlClick, Bk, ahk_id %k_ID%, , LEFT, 1, D
  157. KeyWait, Backspace
  158. ControlClick, Bk, ahk_id %k_ID%, , LEFT, 1, U
  159. return
  160. <em>; LShift and RShift are used rather than &quot;Shift&quot; because when used as a hotkey,
  161. ; &quot;Shift&quot; would default to firing upon release of the key (in older AHK versions):</em>
  162. ~*LShift::
  163. ~*RShift::
  164. ~*LCtrl:: <em>; Must use Ctrl not Control to match button names.</em>
  165. ~*RCtrl::
  166. ~*LAlt::
  167. ~*RAlt::
  168. ~*LWin::
  169. ~*RWin::
  170. StringTrimLeft, k_ThisHotkey, A_ThisHotkey, 3
  171. ControlClick, %k_ThisHotkey%, ahk_id %k_ID%, , LEFT, 1, D
  172. KeyWait, %k_ThisHotkey%
  173. ControlClick, %k_ThisHotkey%, ahk_id %k_ID%, , LEFT, 1, U
  174. return
  175. ~*,::
  176. ~*'::
  177. ~*Space::
  178. ~*Enter::
  179. ~*Tab::
  180. k_KeyPress:
  181. StringReplace, k_ThisHotkey, A_ThisHotkey, ~
  182. StringReplace, k_ThisHotkey, k_ThisHotkey, *
  183. SetTitleMatchMode, 3 <em>; Prevents the T and B keys from being confused with Tab and Backspace.</em>
  184. ControlClick, %k_ThisHotkey%, ahk_id %k_ID%, , LEFT, 1, D
  185. KeyWait, %k_ThisHotkey%
  186. ControlClick, %k_ThisHotkey%, ahk_id %k_ID%, , LEFT, 1, U
  187. Return
  188. k_ShowHide:
  189. if k_IsVisible = y
  190. {
  191. Gui, Cancel
  192. Menu, Tray, Rename, %k_MenuItemHide%, %k_MenuItemShow%
  193. k_IsVisible = n
  194. }
  195. else
  196. {
  197. Gui, Show
  198. Menu, Tray, Rename, %k_MenuItemShow%, %k_MenuItemHide%
  199. k_IsVisible = y
  200. }
  201. return
  202. GuiClose:
  203. k_MenuExit:
  204. ExitApp
  205. </pre>
  206. </body>
  207. </html>