anonymous1184

OSK

Jan 19th, 2021 (edited)
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; On-Screen Keyboard version 3 (requires XP/2k/NT), enhanced by /u/anonymous1184 & /u/KeronCyst (edit X in "BackgroundX" in line 608 to change the flash color)
  2. ; https://autohotkey.com/board/topic/94703-another-approach-to-a-virtual-keyboard/
  3. ; Made from Jon's original code (http://www.autohotkey.com) with blinking by Lehnemann.
  4. ;
  5. ; The main objective of the program remains the same:
  6. ; To create a virtual visualization of the keyboard and to show which key is being pressed.
  7. ;
  8. ; The code has small updates and the main change was the way the virtual keyboard
  9. ; indicates which key was pressed. The original method, the easiest, used left-clicks
  10. ; on the virtual keyboard buttons to indicate which key was pressed. What I used is
  11. ; based on the use of two layers of controls (one with progress bars and one with
  12. ; buttons) to flash the button being pressed.
  13. ;
  14. ; With the F2 hotkey, I show another approach to the flashing of a control.
  15. ;
  16. ; In the same way, the size of the on-screen keyboard can be customized
  17. ; at the top of the script (through the font size). Also, you can
  18. ; double-click the tray icon to show or hide the keyboard.
  19.  
  20. ;---- Configuration Section: Customize the size of the on-screen keyboard and
  21. ; other options here.
  22.  
  23. ; Changing this font size will resize the keyboard:
  24. k_FontSize = 10
  25. k_FontName = Verdana  ; This can be blank to use the system's default font.
  26. k_FontStyle = Bold    ; Example of an alternative: Italic Underline
  27.  
  28. ; Names for the tray menu items:
  29. k_MenuItemHide := "Hide keyboard"
  30. k_MenuItemShow := "Show keyboard"
  31.  
  32. ; To have the keyboard appear on a monitor other than the primary, specify
  33. ; a number such as 2 for the following variable.  Leave it blank to use
  34. ; the primary:
  35. k_Monitor =
  36.  
  37. ;---- End of configuration section.  Don't change anything below this point
  38. ; unless you want to alter the basic nature of the script.
  39.  
  40.  
  41. ;---- Alter the tray icon menu:
  42. Menu, Tray, Add, %k_MenuItemHide%, k_ShowHide
  43. Menu, Tray, Add, &Exit, k_MenuExit
  44. Menu, Tray, Default, %k_MenuItemHide%
  45. Menu, Tray, NoStandard
  46.  
  47. ;---- Calculate object dimensions based on chosen font size:
  48. k_KeyWidth := k_FontSize * 3
  49. k_KeyHeight := k_FontSize * 3
  50. k_KeyWidth0 := k_KeyWidth * 2
  51.  
  52. ;    Spacing to be used between the keys.
  53. k_KeyMargin := k_FontSize // 6
  54.  
  55. ;    The total width of the keyboard to be assembled in terms of the keys and the spacing between them.
  56. width := 15 * k_KeyWidth + 14 * k_KeyMargin
  57.  
  58. ;   Special keys. Along with the size of the default key, they help define the virtual keyboard
  59. ;   (depends on the type of keyboard).
  60. ;   Notice that both the initial and final keys of each row are important to build the virtual keyboard.
  61. k_KeyWidthHalf := k_KeyWidth / 2
  62. k_TabW := k_FontSize * 4
  63. k_CapsW := k_KeyWidth + k_KeyMargin + k_KeyWidthHalf
  64. k_ShiftW := 2 * k_KeyWidth + k_KeyMargin
  65. k_SpacebarWidth := k_FontSize * 17
  66. k_LastKeyWidth := width - ( k_TabW + 12 * k_KeyWidth + 13 * k_KeyMargin )
  67. k_EnterWidth := width - ( k_CapsW + 11 * k_KeyWidth + 12 * k_KeyMargin )
  68. k_LastShiftWidth := width - ( k_ShiftW + 10 * k_KeyWidth + 11 * k_KeyMargin )
  69. k_LastCtrlWidth := width - ( 6 * k_TabW + k_SpacebarWidth + 7 * k_KeyMargin )
  70.  
  71. ;   Only a facilitator for creating GUI.
  72. k_KeySize = w%k_KeyWidth% h%k_KeyHeight%
  73. k_KeySize0 = w%k_KeyWidth0% h%k_KeyHeight%
  74. k_Position = x+%k_KeyMargin% %k_KeySize%
  75. k_Numpad0 = x+%k_KeyMargin% %k_KeySize0%
  76.  
  77. ;   This table is used to relate the hotkeys pressed with their progress bars,
  78. ;   to flash them on the ANSI-style keyboard.
  79. k_Characters := {"" : ""
  80.     , "``"          :  1
  81.     , 1             :  2
  82.     , 2             :  3
  83.     , 3             :  4
  84.     , 4             :  5
  85.     , 5             :  6
  86.     , 6             :  7
  87.     , 7             :  8
  88.     , 8             :  9
  89.     , 9             : 10
  90.     , 0             : 11
  91.     , "-"           : 12
  92.     , "="           : 13
  93.     , "Backspace"   : 14
  94.     , "Tab"         : 15
  95.     , "Q"           : 16
  96.     , "W"           : 17
  97.     , "E"           : 18
  98.     , "R"           : 19
  99.     , "T"           : 20
  100.     , "Y"           : 21
  101.     , "U"           : 22
  102.     , "I"           : 23
  103.     , "O"           : 24
  104.     , "P"           : 25
  105.     , "["           : 26
  106.     , "]"           : 27
  107.     , "\"           : 28
  108.     , "CapsLock"    : 29
  109.     , "A"           : 30
  110.     , "S"           : 31
  111.     , "D"           : 32
  112.     , "F"           : 33
  113.     , "G"           : 34
  114.     , "H"           : 35
  115.     , "J"           : 36
  116.     , "K"           : 37
  117.     , "L"           : 38
  118.     , ";"           : 39
  119.     , "'"           : 40
  120.     , "Enter"       : 41
  121.     , "LShift"      : 42
  122.     , "Z"           : 43
  123.     , "X"           : 44
  124.     , "C"           : 45
  125.     , "V"           : 46
  126.     , "B"           : 47
  127.     , "N"           : 48
  128.     , "M"           : 49
  129.     , ","           : 50
  130.     , "."           : 51
  131.     , "/"           : 52
  132.     , "RShift"      : 53
  133.     , "LCtrl"       : 54
  134.     , "LWin"        : 55
  135.     , "LAlt"        : 56
  136.     , "Space"       : 57
  137.     , "RAlt"        : 58
  138.     , "RWin"        : 59
  139.     , "AppsKey"     : 60
  140.     , "RCtrl"       : 61
  141.     , "Insert"      : 62
  142.     , "Home"        : 63
  143.     , "PgUp"        : 64
  144.     , "Delete"      : 65
  145.     , "End"         : 66
  146.     , "PgDn"        : 67
  147.     , "Up"          : 68
  148.     , "Left"        : 69
  149.     , "Down"        : 70
  150.     , "Right"       : 71
  151.     , "NumLock"     : 72
  152.     , "NumpadDiv"   : 73
  153.     , "NumpadMult"  : 74
  154.     , "NumpadSub"   : 75
  155.     , "Numpad7"     : 76
  156.     , "Numpad8"     : 77
  157.     , "Numpad9"     : 78
  158.     , "NumpadAdd"   : 79
  159.     , "Numpad4"     : 80
  160.     , "Numpad5"     : 81
  161.     , "Numpad6"     : 82
  162.     , "Numpad1"     : 83
  163.     , "Numpad2"     : 84
  164.     , "Numpad3"     : 85
  165.     , "NumpadEnter" : 86
  166.     , "Numpad0"     : 87
  167.     , "NumpadDot"   : 88 }
  168.  
  169. labels := { ""     : ""
  170.     , "AppsKey"    : "App"
  171.     , "BackSpace"  : "🡄"
  172.     , "CapsLock"   : "Caps"
  173.     , "Delete"     : "Del"
  174.     , "Down"       : "⮟"
  175.     , "End"        : "⇲"
  176.     , "Home"       : "⇱"
  177.     , "Insert"     : "Ins"
  178.     , "LAlt"       : "Alt"
  179.     , "LCtrl"      : "lCtrl"
  180.     , "Left"       : "⮜"
  181.     , "LShift"     : "lShift"
  182.     , "LWin"       : "lWin"
  183.     , "NumLock"    : "🔒"
  184.     , "Numpad0"    : "𝟎"
  185.     , "Numpad1"    : "𝟏"
  186.     , "Numpad2"    : "𝟐"
  187.     , "Numpad3"    : "𝟑"
  188.     , "Numpad4"    : "𝟒"
  189.     , "Numpad5"    : "𝟓"
  190.     , "Numpad6"    : "𝟔"
  191.     , "Numpad7"    : "𝟕"
  192.     , "Numpad8"    : "𝟖"
  193.     , "Numpad9"    : "𝟗"
  194.     , "NumpadAdd"  : "+"
  195.     , "NumpadDiv"  : "/"
  196.     , "NumpadDot"  : "․"
  197.     , "NumpadEnter": "Ent"
  198.     , "NumpadMult" : "*"
  199.     , "NumpadSub"  : "–"
  200.     , "PgDn"       : "PD"
  201.     , "PgUp"       : "PU"
  202.     , "RAlt"       : "rAlt"
  203.     , "RCtrl"      : "rCtrl"
  204.     , "Right"      : "⮞"
  205.     , "RShift"     : "rShift"
  206.     , "RWin"       : "rWin"
  207.     , "Tab"        : "⭾"
  208.     , "Up"         : "⮝" }
  209.  
  210. ;---- Create a GUI window for the on-screen keyboard:
  211. Gui, Font, s%k_FontSize% %k_FontStyle%, %k_FontName%
  212. Gui, -Caption +AlwaysOnTop -MaximizeBox +ToolWindow
  213.  
  214. ;   About keyboards: The tab and ctrl have the same size, all the buttons on the far right fit to the size of the
  215. ;   keyboard (dictated by the first line), the left shift has the same size of the backspace (Western keyboards),
  216. ;   the window size is given by x1 + 15 * + 14 * wKey kMargin and y1 + 5 * 4 * + hKey kMargin (where x1 and y1 are
  217. ;   the coordinates of the first key on the top left of the keyboard).
  218.  
  219. ;    We created two layers of controls, one below the other. The bottom layer containing the progresses bar that
  220. ;   will be used to generate the blinking effect. And the top layer represent the buttons themselves.
  221.  
  222. ;   The first row of the virtual keyboard.
  223. Gui, Add, Progress, section xm ym %k_KeySize% Disabled vprg1
  224. Gui, Add, Progress, %k_Position% Disabled vprg2
  225. Gui, Add, Progress, %k_Position% Disabled vprg3
  226. Gui, Add, Progress, %k_Position% Disabled vprg4
  227. Gui, Add, Progress, %k_Position% Disabled vprg5
  228. Gui, Add, Progress, %k_Position% Disabled vprg6
  229. Gui, Add, Progress, %k_Position% Disabled vprg7
  230. Gui, Add, Progress, %k_Position% Disabled vprg8
  231. Gui, Add, Progress, %k_Position% Disabled vprg9
  232. Gui, Add, Progress, %k_Position% Disabled vprg10
  233. Gui, Add, Progress, %k_Position% Disabled vprg11
  234. Gui, Add, Progress, %k_Position% Disabled vprg12
  235. Gui, Add, Progress, %k_Position% Disabled vprg13
  236. Gui, Add, Progress, x+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight% Disabled vprg14
  237. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  238. Gui, Add, Progress, %k_Position% Disabled vprg62 ; Insert
  239. Gui, Add, Progress, %k_Position% Disabled vprg63 ; Home
  240. Gui, Add, Progress, %k_Position% Disabled vprg64 ; PgUp
  241. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  242. Gui, Add, Progress, %k_Position% Disabled vprg72 ; NumLock
  243. Gui, Add, Progress, %k_Position% Disabled vprg73 ; NumpadDiv
  244. Gui, Add, Progress, %k_Position% Disabled vprg74 ; NumpadMult
  245. Gui, Add, Progress, %k_Position% Disabled vprg75 ; NumpadSub
  246.  
  247. ;   The second row.
  248. Gui, Add, Progress, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg15
  249. Gui, Add, Progress, %k_Position% Disabled vprg16
  250. Gui, Add, Progress, %k_Position% Disabled vprg17
  251. Gui, Add, Progress, %k_Position% Disabled vprg18
  252. Gui, Add, Progress, %k_Position% Disabled vprg19
  253. Gui, Add, Progress, %k_Position% Disabled vprg20
  254. Gui, Add, Progress, %k_Position% Disabled vprg21
  255. Gui, Add, Progress, %k_Position% Disabled vprg22
  256. Gui, Add, Progress, %k_Position% Disabled vprg23
  257. Gui, Add, Progress, %k_Position% Disabled vprg24
  258. Gui, Add, Progress, %k_Position% Disabled vprg25
  259. Gui, Add, Progress, %k_Position% Disabled vprg26
  260. Gui, Add, Progress, %k_Position% Disabled vprg27
  261. Gui, Add, Progress, x+%k_KeyMargin% w%k_LastKeyWidth% h%k_KeyHeight% Disabled vprg28
  262. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  263. Gui, Add, Progress, %k_Position% Disabled vprg65 ; Delete
  264. Gui, Add, Progress, %k_Position% Disabled vprg66 ; End
  265. Gui, Add, Progress, %k_Position% Disabled vprg67 ; PgDn
  266. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  267. Gui, Add, Progress, %k_Position% Disabled vprg76 ; Numpad7
  268. Gui, Add, Progress, %k_Position% Disabled vprg77 ; Numpad8
  269. Gui, Add, Progress, %k_Position% Disabled vprg78 ; Numpad9
  270. Gui, Add, Progress, %k_Position% Disabled vprg79 ; NumpadAdd
  271.  
  272. ;   The third row.
  273. Gui, Add, Progress, xm y+%k_KeyMargin% w%k_CapsW% h%k_KeyHeight% Disabled vprg29
  274. Gui, Add, Progress, %k_Position% Disabled vprg30
  275. Gui, Add, Progress, %k_Position% Disabled vprg31
  276. Gui, Add, Progress, %k_Position% Disabled vprg32
  277. Gui, Add, Progress, %k_Position% Disabled vprg33
  278. Gui, Add, Progress, %k_Position% Disabled vprg34
  279. Gui, Add, Progress, %k_Position% Disabled vprg35
  280. Gui, Add, Progress, %k_Position% Disabled vprg36
  281. Gui, Add, Progress, %k_Position% Disabled vprg37
  282. Gui, Add, Progress, %k_Position% Disabled vprg38
  283. Gui, Add, Progress, %k_Position% Disabled vprg39
  284. Gui, Add, Progress, %k_Position% Disabled vprg40
  285. Gui, Add, Progress, x+%k_KeyMargin% w%k_EnterWidth% h%k_KeyHeight% Disabled vprg41
  286. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  287. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  288. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  289. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  290. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  291. Gui, Add, Progress, %k_Position% Disabled vprg80 ; Numpad4
  292. Gui, Add, Progress, %k_Position% Disabled vprg81 ; Numpad5
  293. Gui, Add, Progress, %k_Position% Disabled vprg82 ; Numpad6
  294.  
  295. ;   The fourth row.
  296. Gui, Add, Progress, xm y+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight% Disabled vprg42
  297. Gui, Add, Progress, %k_Position% Disabled vprg43
  298. Gui, Add, Progress, %k_Position% Disabled vprg44
  299. Gui, Add, Progress, %k_Position% Disabled vprg45
  300. Gui, Add, Progress, %k_Position% Disabled vprg46
  301. Gui, Add, Progress, %k_Position% Disabled vprg47
  302. Gui, Add, Progress, %k_Position% Disabled vprg48
  303. Gui, Add, Progress, %k_Position% Disabled vprg49
  304. Gui, Add, Progress, %k_Position% Disabled vprg50
  305. Gui, Add, Progress, %k_Position% Disabled vprg51
  306. Gui, Add, Progress, %k_Position% Disabled vprg52
  307. Gui, Add, Progress, x+%k_KeyMargin% w%k_LastShiftWidth% h%k_KeyHeight% Disabled vprg53
  308. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  309. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  310. Gui, Add, Progress, %k_Position% Disabled vprg68 ; Up
  311. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  312. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  313. Gui, Add, Progress, %k_Position% Disabled vprg83 ; Numpad1
  314. Gui, Add, Progress, %k_Position% Disabled vprg84 ; Numpad2
  315. Gui, Add, Progress, %k_Position% Disabled vprg85 ; Numpad3
  316. Gui, Add, Progress, %k_Position% Disabled vprg86 ; NumpadEnter
  317.  
  318. ;   The last row of keys.
  319. Gui, Add, Progress, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg54
  320. Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg55
  321. Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg56
  322. Gui, Add, Progress, x+%k_KeyMargin% w%k_SpacebarWidth% h%k_KeyHeight% Disabled vprg57
  323. Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg58
  324. Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg59
  325. Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg60
  326. Gui, Add, Progress, x+%lastPos% w%k_LastCtrlWidth% h%k_KeyHeight% Disabled vprg61
  327. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  328. Gui, Add, Progress, %k_Position% Disabled vprg69 ; Left
  329. Gui, Add, Progress, %k_Position% Disabled vprg70 ; Down
  330. Gui, Add, Progress, %k_Position% Disabled vprg71 ; Right
  331. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  332. Gui, Add, Progress, %k_Numpad0% Disabled vprg87 ; Numpad0
  333. Gui, Add, Progress, %k_Position% Disabled vprg88 ; NumpadDot
  334.  
  335. ;---- Add a button for each key. Position the first button with absolute
  336. ; coordinates so that all other buttons can be positioned relative to it:
  337. ;   The first row of the virtual keyboard.
  338. Gui, Add, Button, section xm ym %k_KeySize%, ``
  339. Gui, Add, Button, %k_Position%, 1
  340. Gui, Add, Button, %k_Position%, 2
  341. Gui, Add, Button, %k_Position%, 3
  342. Gui, Add, Button, %k_Position%, 4
  343. Gui, Add, Button, %k_Position%, 5
  344. Gui, Add, Button, %k_Position%, 6
  345. Gui, Add, Button, %k_Position%, 7
  346. Gui, Add, Button, %k_Position%, 8
  347. Gui, Add, Button, %k_Position%, 9
  348. Gui, Add, Button, %k_Position%, 0
  349. Gui, Add, Button, %k_Position%, -
  350. Gui, Add, Button, %k_Position%, =
  351. Gui, Add, Button, x+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight%, % labels["Backspace"]
  352. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  353. Gui, Add, Button, %k_Position%, Ins
  354. Gui, Add, Button, %k_Position%, % labels["Home"]
  355. Gui, Add, Button, %k_Position%, % labels["PgUp"]
  356. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  357. Gui, Add, Button, %k_Position%, % labels["NumLock"]
  358. Gui, Add, Button, %k_Position%, /
  359. Gui, Add, Button, %k_Position%, *
  360. Gui, Add, Button, %k_Position%, % labels["NumpadSub"]
  361.  
  362. ;   The second row.
  363. Gui, Add, Button, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["Tab"]
  364. Gui, Add, Button, %k_Position%, Q
  365. Gui, Add, Button, %k_Position%, W
  366. Gui, Add, Button, %k_Position%, E
  367. Gui, Add, Button, %k_Position%, R
  368. Gui, Add, Button, %k_Position%, T
  369. Gui, Add, Button, %k_Position%, Y
  370. Gui, Add, Button, %k_Position%, U
  371. Gui, Add, Button, %k_Position%, I
  372. Gui, Add, Button, %k_Position%, O
  373. Gui, Add, Button, %k_Position%, P
  374. Gui, Add, Button, %k_Position%, [
  375. Gui, Add, Button, %k_Position%, ]
  376. Gui, Add, Button, x+%k_KeyMargin% w%k_LastKeyWidth% h%k_KeyHeight%, \
  377. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  378. Gui, Add, Button, %k_Position%, Del
  379. Gui, Add, Button, %k_Position%, % labels["End"]
  380. Gui, Add, Button, %k_Position%, % labels["PgDn"]
  381. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  382. Gui, Add, Button, %k_Position%, % labels["Numpad7"]
  383. Gui, Add, Button, %k_Position%, % labels["Numpad8"]
  384. Gui, Add, Button, %k_Position%, % labels["Numpad9"]
  385. Gui, Add, Button, %k_Position%, +
  386.  
  387. ;   The third row.
  388. Gui, Add, Button, xm y+%k_KeyMargin% w%k_CapsW% h%k_KeyHeight%, % labels["CapsLock"]
  389. Gui, Add, Button, %k_Position%, A
  390. Gui, Add, Button, %k_Position%, S
  391. Gui, Add, Button, %k_Position%, D
  392. Gui, Add, Button, %k_Position%, F
  393. Gui, Add, Button, %k_Position%, G
  394. Gui, Add, Button, %k_Position%, H
  395. Gui, Add, Button, %k_Position%, J
  396. Gui, Add, Button, %k_Position%, K
  397. Gui, Add, Button, %k_Position%, L
  398. Gui, Add, Button, %k_Position%, `;
  399. Gui, Add, Button, %k_Position%, '
  400. Gui, Add, Button, x+%k_KeyMargin% w%k_EnterWidth% h%k_KeyHeight%, Enter
  401. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  402. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  403. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  404. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  405. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  406. Gui, Add, Button, %k_Position%, % labels["Numpad4"]
  407. Gui, Add, Button, %k_Position%, % labels["Numpad5"]
  408. Gui, Add, Button, %k_Position%, % labels["Numpad6"]
  409.  
  410. ;   The fourth row.
  411. Gui, Add, Button, xm y+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight%, % labels["LShift"]
  412. Gui, Add, Button, %k_Position%, Z
  413. Gui, Add, Button, %k_Position%, X
  414. Gui, Add, Button, %k_Position%, C
  415. Gui, Add, Button, %k_Position%, V
  416. Gui, Add, Button, %k_Position%, B
  417. Gui, Add, Button, %k_Position%, N
  418. Gui, Add, Button, %k_Position%, M
  419. Gui, Add, Button, %k_Position%, `,
  420. Gui, Add, Button, %k_Position%, .
  421. Gui, Add, Button, %k_Position%, /
  422. Gui, Add, Button, x+%k_KeyMargin% w%k_LastShiftWidth% h%k_KeyHeight%, % labels["RShift"]
  423. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  424. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  425. Gui, Add, Button, %k_Position%, % labels["Up"]
  426. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  427. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  428. Gui, Add, Button, %k_Position%, % labels["Numpad1"]
  429. Gui, Add, Button, %k_Position%, % labels["Numpad2"]
  430. Gui, Add, Button, %k_Position%, % labels["Numpad3"]
  431. Gui, Add, Button, %k_Position%, % labels["NumpadEnter"]
  432.  
  433. ;   The last row of keys.
  434. Gui, Add, Button, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["LCtrl"]
  435. Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["LWin"]
  436. Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["LAlt"]
  437. Gui, Add, Button, x+%k_KeyMargin% w%k_SpacebarWidth% h%k_KeyHeight%, Space
  438. Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["RAlt"]
  439. Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["RWin"]
  440. Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["AppsKey"]
  441. Gui, Add, Button, x+%k_KeyMargin% w%k_LastCtrlWidth% h%k_KeyHeight%, % labels["RCtrl"]
  442. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  443. Gui, Add, Button, %k_Position%, % labels["Left"]
  444. Gui, Add, Button, %k_Position%, % labels["Down"]
  445. Gui, Add, Button, %k_Position%, % labels["Right"]
  446. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  447. Gui, Add, Button, %k_Numpad0%, % labels["Numpad0"]
  448. Gui, Add, Button, %k_Position%, % labels["NumpadDot"]
  449.  
  450. ;---- Show the window centered and not active (to avoid changing the current window's focus):
  451. Gui, Show, xCenter NoActivate, Virtual Keyboard View
  452.  
  453. ;   Creates and gives a value to the variable that controls whether the virtual keyboard is
  454. ;   displayed on the screen or not.
  455. k_IsVisible = y
  456.  
  457. ;    Get the window's Width and Height through the GUI's name.
  458. WinGetPos,,, k_WindowWidth, k_WindowHeight, Virtual Keyboard View
  459.  
  460. ;---- Position the keyboard at the bottom of the screen (taking into account
  461. ; the position of the taskbar):
  462. SysGet, k_WorkArea, MonitorWorkArea, %k_Monitor%
  463.  
  464. ; Calculate window's X-position:
  465. k_WindowX = %k_WorkAreaRight%
  466. k_WindowX -= %k_WorkAreaLeft%  ; Now k_WindowX contains the width of this monitor.
  467. k_WindowX -= %k_WindowWidth%
  468. k_WindowX /= 2  ; Calculate position to center it horizontally.
  469. ; The following is done in case the window will be on a non-primary monitor
  470. ; or if the taskbar is anchored on the left side of the screen:
  471. k_WindowX += %k_WorkAreaLeft%
  472.  
  473. ; Calculate window's Y-position:
  474. k_WindowY = %k_WorkAreaBottom%
  475. k_WindowY -= %k_WindowHeight%
  476.  
  477. ;   Move the window to the bottom center position of the monitor.
  478. WinMove, Virtual Keyboard View,, %k_WindowX%, %k_WindowY%
  479.  
  480. ;   Makes the window transparent (the number regulates the transparency).
  481. WinSet, Transparent, 150, Virtual Keyboard View
  482.  
  483. ;---- Set all keys as hotkeys. See www.asciitable.com
  484. k_n = 1
  485. k_ASCII = 45
  486.  
  487. Loop {
  488.     ; Change number into a real character.
  489.     k_char := Chr(k_ASCII)
  490.  
  491.     ; These keys are only accessible using modifier keys, that's why we're escaping them.
  492.     if k_char not in <,>,^,`,
  493.         Hotkey, ~*%k_char%, blinkButton
  494.         ; In the above, the asterisk prefix allows the key to be detected regardless
  495.         ; of whether the user is holding down modifier keys such as Control and Shift.
  496.         ; And without "~" the character wouldn't be shown in the window.
  497.  
  498.     k_ASCII++
  499.  
  500.     ; Stop looping in the last key of the keyboard ("]").
  501. } until (k_ASCII = 94)
  502.  
  503. return ; End of auto-execute section.
  504.  
  505.  
  506. ;---- When a key is pressed by the user, blink the corresponding button on-screen:
  507.  
  508. ;   Fires the corresponding subroutine when we press the specials keys and the normal ones.
  509. ~*`::
  510. ~*Backspace::
  511. ~*Tab::
  512. ~*CapsLock::
  513. ~*'::
  514. ~*Enter::
  515. ~*LShift::
  516. ~*,::
  517. ~*RShift::
  518. ~*LCtrl::  ; Must use Ctrl, not Control, to match button names.
  519. ~*LWin::
  520. ~*LAlt::
  521. ~*Space::
  522. ~*RAlt::
  523. ~*RWin::
  524. ~*AppsKey::
  525. ~*RCtrl::
  526.  
  527. ~*Insert::
  528. ~*Home::
  529. ~*PgUp::
  530. ~*Delete::
  531. ~*End::
  532. ~*PgDn::
  533.  
  534. ~*Up::
  535. ~*Left::
  536. ~*Down::
  537. ~*Right::
  538.  
  539. ~*NumLock::
  540. ~*NumpadDiv::
  541. ~*NumpadMult::
  542. ~*Numpad7::
  543. ~*Numpad8::
  544. ~*Numpad9::
  545. ~*Numpad4::
  546. ~*Numpad5::
  547. ~*Numpad6::
  548. ~*Numpad1::
  549. ~*Numpad2::
  550. ~*Numpad3::
  551. ~*Numpad0::
  552. ~*NumpadDot::
  553.  
  554. ~*NumpadSub::
  555. ~*NumpadAdd::
  556. ~*NumpadEnter::blinkButton()
  557.  
  558.  
  559. ; Show or hide the keyboard if the variable is "y" or "n".
  560. k_ShowHide:
  561.    if k_IsVisible = y
  562.     {
  563.         ; Hide the keyboard gui, change the tray option's name
  564.         ; and update the variable that control the visibility.
  565.         Gui, Cancel
  566.         Menu, Tray, Rename, %k_MenuItemHide%, %k_MenuItemShow%
  567.         k_IsVisible = n
  568.     }
  569.     else
  570.     {
  571.         ; The contrary of the lines above.
  572.         Gui, Show
  573.         Menu, Tray, Rename, %k_MenuItemShow%, %k_MenuItemHide%
  574.         k_IsVisible = y
  575.     }
  576. return
  577.  
  578. ;    Function used to flash the button.
  579. blinkButton()
  580. {
  581.     ; Erase the key ("~*").
  582.     StringReplace, k_ThisHotkey, A_ThisHotkey, ~*
  583.  
  584.     ; Prevents the T and B keys from being confused as Tab and Backspace.
  585.     SetTitleMatchMode, 3
  586.  
  587.     ; Find the variable's index for the control.
  588.     global k_Characters
  589.     index := k_Characters[k_ThisHotkey]
  590.  
  591.     ; Change the color of the corresponding progress bar to red
  592.     ; (beginning of the flashing's process).
  593.     guicontrol, +BackgroundRed, prg%index%
  594.  
  595.     ; Wait for the release of the key.
  596.     KeyWait, %k_ThisHotkey%
  597.  
  598.     ; Return the color of the progress bar to the default (ending of the flashing's process).
  599.     guicontrol, -Background, prg%index%
  600.  
  601.     ; Redraw the button on release (needed because the buttons' names differ from the hotkeys' names).
  602.  
  603.     global labels
  604.     guicontrol, MoveDraw, % (labels[k_ThisHotkey] ? labels[k_ThisHotkey] : k_ThisHotkey)
  605. }
  606.  
  607. ;   Leave the script (with the Escape key,
  608. ;   the window's x button and Exit option in the tray menu icon).
  609. GUIEscape:
  610. GuiClose:
  611. k_MenuExit:
  612.    ExitApp
  613.  
Add Comment
Please, Sign In to add comment