Advertisement
anonymous1184

OSK v2

Jan 20th, 2021 (edited)
373
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. zwnbs := Chr(8204) ; Zero-width non-breaking space
  170. labels := { ""     : ""
  171.     , "AppsKey"    : "App"
  172.     , "BackSpace"  : "🡄"
  173.     , "CapsLock"   : "Caps"
  174.     , "Delete"     : "Del"
  175.     , "Down"       : "⮟"
  176.     , "End"        : "⇲"
  177.     , "Home"       : "⇱"
  178.     , "Insert"     : "Ins"
  179.     , "LAlt"       : "Alt"
  180.     , "LCtrl"      : "Ctrl"
  181.     , "Left"       : "⮜"
  182.     , "LShift"     : "Shift"
  183.     , "LWin"       : "Win"
  184.     , "NumLock"    : "🔒"
  185.     , "Numpad0"    : "0" zwnbs
  186.     , "Numpad1"    : "1" zwnbs
  187.     , "Numpad2"    : "2" zwnbs
  188.     , "Numpad3"    : "3" zwnbs
  189.     , "Numpad4"    : "4" zwnbs
  190.     , "Numpad5"    : "5" zwnbs
  191.     , "Numpad6"    : "6" zwnbs
  192.     , "Numpad7"    : "7" zwnbs
  193.     , "Numpad8"    : "8" zwnbs
  194.     , "Numpad9"    : "9" zwnbs
  195.     , "NumpadAdd"  : "+"
  196.     , "NumpadDiv"  : "/" zwnbs
  197.     , "NumpadDot"  : "." zwnbs
  198.     , "NumpadEnter": "Ent"
  199.     , "NumpadMult" : "*"
  200.     , "NumpadSub"  : "-" zwnbs
  201.     , "PgDn"       : "PD"
  202.     , "PgUp"       : "PU"
  203.     , "RAlt"       : "Alt" zwnbs
  204.     , "RCtrl"      : "Ctrl" zwnbs
  205.     , "Right"      : "⮞"
  206.     , "RShift"     : "Shift" zwnbs
  207.     , "RWin"       : "Win" zwnbs
  208.     , "Tab"        : "⭾"
  209.     , "Up"         : "⮝" }
  210.  
  211. ;---- Create a GUI window for the on-screen keyboard:
  212. Gui, Font, s%k_FontSize% %k_FontStyle%, %k_FontName%
  213. Gui, -Caption +AlwaysOnTop -MaximizeBox +ToolWindow
  214.  
  215. ;   About keyboards: The tab and ctrl have the same size, all the buttons on the far right fit to the size of the
  216. ;   keyboard (dictated by the first line), the left shift has the same size of the backspace (Western keyboards),
  217. ;   the window size is given by x1 + 15 * + 14 * wKey kMargin and y1 + 5 * 4 * + hKey kMargin (where x1 and y1 are
  218. ;   the coordinates of the first key on the top left of the keyboard).
  219.  
  220. ;    We created two layers of controls, one below the other. The bottom layer containing the progresses bar that
  221. ;   will be used to generate the blinking effect. And the top layer represent the buttons themselves.
  222.  
  223. ;   The first row of the virtual keyboard.
  224. Gui, Add, Progress, section xm ym %k_KeySize% Disabled vprg1
  225. Gui, Add, Progress, %k_Position% Disabled vprg2
  226. Gui, Add, Progress, %k_Position% Disabled vprg3
  227. Gui, Add, Progress, %k_Position% Disabled vprg4
  228. Gui, Add, Progress, %k_Position% Disabled vprg5
  229. Gui, Add, Progress, %k_Position% Disabled vprg6
  230. Gui, Add, Progress, %k_Position% Disabled vprg7
  231. Gui, Add, Progress, %k_Position% Disabled vprg8
  232. Gui, Add, Progress, %k_Position% Disabled vprg9
  233. Gui, Add, Progress, %k_Position% Disabled vprg10
  234. Gui, Add, Progress, %k_Position% Disabled vprg11
  235. Gui, Add, Progress, %k_Position% Disabled vprg12
  236. Gui, Add, Progress, %k_Position% Disabled vprg13
  237. Gui, Add, Progress, x+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight% Disabled vprg14
  238. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  239. Gui, Add, Progress, %k_Position% Disabled vprg62 ; Insert
  240. Gui, Add, Progress, %k_Position% Disabled vprg63 ; Home
  241. Gui, Add, Progress, %k_Position% Disabled vprg64 ; PgUp
  242. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  243. Gui, Add, Progress, %k_Position% Disabled vprg72 ; NumLock
  244. Gui, Add, Progress, %k_Position% Disabled vprg73 ; NumpadDiv
  245. Gui, Add, Progress, %k_Position% Disabled vprg74 ; NumpadMult
  246. Gui, Add, Progress, %k_Position% Disabled vprg75 ; NumpadSub
  247.  
  248. ;   The second row.
  249. Gui, Add, Progress, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg15
  250. Gui, Add, Progress, %k_Position% Disabled vprg16
  251. Gui, Add, Progress, %k_Position% Disabled vprg17
  252. Gui, Add, Progress, %k_Position% Disabled vprg18
  253. Gui, Add, Progress, %k_Position% Disabled vprg19
  254. Gui, Add, Progress, %k_Position% Disabled vprg20
  255. Gui, Add, Progress, %k_Position% Disabled vprg21
  256. Gui, Add, Progress, %k_Position% Disabled vprg22
  257. Gui, Add, Progress, %k_Position% Disabled vprg23
  258. Gui, Add, Progress, %k_Position% Disabled vprg24
  259. Gui, Add, Progress, %k_Position% Disabled vprg25
  260. Gui, Add, Progress, %k_Position% Disabled vprg26
  261. Gui, Add, Progress, %k_Position% Disabled vprg27
  262. Gui, Add, Progress, x+%k_KeyMargin% w%k_LastKeyWidth% h%k_KeyHeight% Disabled vprg28
  263. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  264. Gui, Add, Progress, %k_Position% Disabled vprg65 ; Delete
  265. Gui, Add, Progress, %k_Position% Disabled vprg66 ; End
  266. Gui, Add, Progress, %k_Position% Disabled vprg67 ; PgDn
  267. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  268. Gui, Add, Progress, %k_Position% Disabled vprg76 ; Numpad7
  269. Gui, Add, Progress, %k_Position% Disabled vprg77 ; Numpad8
  270. Gui, Add, Progress, %k_Position% Disabled vprg78 ; Numpad9
  271. Gui, Add, Progress, %k_Position% Disabled vprg79 ; NumpadAdd
  272.  
  273. ;   The third row.
  274. Gui, Add, Progress, xm y+%k_KeyMargin% w%k_CapsW% h%k_KeyHeight% Disabled vprg29
  275. Gui, Add, Progress, %k_Position% Disabled vprg30
  276. Gui, Add, Progress, %k_Position% Disabled vprg31
  277. Gui, Add, Progress, %k_Position% Disabled vprg32
  278. Gui, Add, Progress, %k_Position% Disabled vprg33
  279. Gui, Add, Progress, %k_Position% Disabled vprg34
  280. Gui, Add, Progress, %k_Position% Disabled vprg35
  281. Gui, Add, Progress, %k_Position% Disabled vprg36
  282. Gui, Add, Progress, %k_Position% Disabled vprg37
  283. Gui, Add, Progress, %k_Position% Disabled vprg38
  284. Gui, Add, Progress, %k_Position% Disabled vprg39
  285. Gui, Add, Progress, %k_Position% Disabled vprg40
  286. Gui, Add, Progress, x+%k_KeyMargin% w%k_EnterWidth% h%k_KeyHeight% Disabled vprg41
  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 ; Make some space
  292. Gui, Add, Progress, %k_Position% Disabled vprg80 ; Numpad4
  293. Gui, Add, Progress, %k_Position% Disabled vprg81 ; Numpad5
  294. Gui, Add, Progress, %k_Position% Disabled vprg82 ; Numpad6
  295.  
  296. ;   The fourth row.
  297. Gui, Add, Progress, xm y+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight% Disabled vprg42
  298. Gui, Add, Progress, %k_Position% Disabled vprg43
  299. Gui, Add, Progress, %k_Position% Disabled vprg44
  300. Gui, Add, Progress, %k_Position% Disabled vprg45
  301. Gui, Add, Progress, %k_Position% Disabled vprg46
  302. Gui, Add, Progress, %k_Position% Disabled vprg47
  303. Gui, Add, Progress, %k_Position% Disabled vprg48
  304. Gui, Add, Progress, %k_Position% Disabled vprg49
  305. Gui, Add, Progress, %k_Position% Disabled vprg50
  306. Gui, Add, Progress, %k_Position% Disabled vprg51
  307. Gui, Add, Progress, %k_Position% Disabled vprg52
  308. Gui, Add, Progress, x+%k_KeyMargin% w%k_LastShiftWidth% h%k_KeyHeight% Disabled vprg53
  309. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  310. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  311. Gui, Add, Progress, %k_Position% Disabled vprg68 ; Up
  312. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  313. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  314. Gui, Add, Progress, %k_Position% Disabled vprg83 ; Numpad1
  315. Gui, Add, Progress, %k_Position% Disabled vprg84 ; Numpad2
  316. Gui, Add, Progress, %k_Position% Disabled vprg85 ; Numpad3
  317. Gui, Add, Progress, %k_Position% Disabled vprg86 ; NumpadEnter
  318.  
  319. ;   The last row of keys.
  320. Gui, Add, Progress, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg54
  321. Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg55
  322. Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg56
  323. Gui, Add, Progress, x+%k_KeyMargin% w%k_SpacebarWidth% h%k_KeyHeight% Disabled vprg57
  324. Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg58
  325. Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg59
  326. Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg60
  327. Gui, Add, Progress, x+%lastPos% w%k_LastCtrlWidth% h%k_KeyHeight% Disabled vprg61
  328. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  329. Gui, Add, Progress, %k_Position% Disabled vprg69 ; Left
  330. Gui, Add, Progress, %k_Position% Disabled vprg70 ; Down
  331. Gui, Add, Progress, %k_Position% Disabled vprg71 ; Right
  332. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  333. Gui, Add, Progress, %k_Numpad0% Disabled vprg87 ; Numpad0
  334. Gui, Add, Progress, %k_Position% Disabled vprg88 ; NumpadDot
  335.  
  336. ;---- Add a button for each key. Position the first button with absolute
  337. ; coordinates so that all other buttons can be positioned relative to it:
  338. ;   The first row of the virtual keyboard.
  339. Gui, Add, Button, section xm ym %k_KeySize%, ``
  340. Gui, Add, Button, %k_Position%, 1
  341. Gui, Add, Button, %k_Position%, 2
  342. Gui, Add, Button, %k_Position%, 3
  343. Gui, Add, Button, %k_Position%, 4
  344. Gui, Add, Button, %k_Position%, 5
  345. Gui, Add, Button, %k_Position%, 6
  346. Gui, Add, Button, %k_Position%, 7
  347. Gui, Add, Button, %k_Position%, 8
  348. Gui, Add, Button, %k_Position%, 9
  349. Gui, Add, Button, %k_Position%, 0
  350. Gui, Add, Button, %k_Position%, -
  351. Gui, Add, Button, %k_Position%, =
  352. Gui, Add, Button, x+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight%, % labels["Backspace"]
  353. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  354. Gui, Add, Button, %k_Position%, Ins
  355. Gui, Add, Button, %k_Position%, % labels["Home"]
  356. Gui, Add, Button, %k_Position%, % labels["PgUp"]
  357. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  358. Gui, Add, Button, %k_Position%, % labels["NumLock"]
  359. Gui, Add, Button, %k_Position%, % labels["NumpadDiv"]
  360. Gui, Add, Button, %k_Position%, *
  361. Gui, Add, Button, %k_Position%, % labels["NumpadSub"]
  362.  
  363. ;   The second row.
  364. Gui, Add, Button, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["Tab"]
  365. Gui, Add, Button, %k_Position%, Q
  366. Gui, Add, Button, %k_Position%, W
  367. Gui, Add, Button, %k_Position%, E
  368. Gui, Add, Button, %k_Position%, R
  369. Gui, Add, Button, %k_Position%, T
  370. Gui, Add, Button, %k_Position%, Y
  371. Gui, Add, Button, %k_Position%, U
  372. Gui, Add, Button, %k_Position%, I
  373. Gui, Add, Button, %k_Position%, O
  374. Gui, Add, Button, %k_Position%, P
  375. Gui, Add, Button, %k_Position%, [
  376. Gui, Add, Button, %k_Position%, ]
  377. Gui, Add, Button, x+%k_KeyMargin% w%k_LastKeyWidth% h%k_KeyHeight%, \
  378. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  379. Gui, Add, Button, %k_Position%, Del
  380. Gui, Add, Button, %k_Position%, % labels["End"]
  381. Gui, Add, Button, %k_Position%, % labels["PgDn"]
  382. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  383. Gui, Add, Button, %k_Position%, % labels["Numpad7"]
  384. Gui, Add, Button, %k_Position%, % labels["Numpad8"]
  385. Gui, Add, Button, %k_Position%, % labels["Numpad9"]
  386. Gui, Add, Button, %k_Position%, +
  387.  
  388. ;   The third row.
  389. Gui, Add, Button, xm y+%k_KeyMargin% w%k_CapsW% h%k_KeyHeight%, % labels["CapsLock"]
  390. Gui, Add, Button, %k_Position%, A
  391. Gui, Add, Button, %k_Position%, S
  392. Gui, Add, Button, %k_Position%, D
  393. Gui, Add, Button, %k_Position%, F
  394. Gui, Add, Button, %k_Position%, G
  395. Gui, Add, Button, %k_Position%, H
  396. Gui, Add, Button, %k_Position%, J
  397. Gui, Add, Button, %k_Position%, K
  398. Gui, Add, Button, %k_Position%, L
  399. Gui, Add, Button, %k_Position%, `;
  400. Gui, Add, Button, %k_Position%, '
  401. Gui, Add, Button, x+%k_KeyMargin% w%k_EnterWidth% h%k_KeyHeight%, Enter
  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, Progress, %k_Position% Disabled ; Make some space
  407. Gui, Add, Button, %k_Position%, % labels["Numpad4"]
  408. Gui, Add, Button, %k_Position%, % labels["Numpad5"]
  409. Gui, Add, Button, %k_Position%, % labels["Numpad6"]
  410.  
  411. ;   The fourth row.
  412. Gui, Add, Button, xm y+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight%, % labels["LShift"]
  413. Gui, Add, Button, %k_Position%, Z
  414. Gui, Add, Button, %k_Position%, X
  415. Gui, Add, Button, %k_Position%, C
  416. Gui, Add, Button, %k_Position%, V
  417. Gui, Add, Button, %k_Position%, B
  418. Gui, Add, Button, %k_Position%, N
  419. Gui, Add, Button, %k_Position%, M
  420. Gui, Add, Button, %k_Position%, `,
  421. Gui, Add, Button, %k_Position%, .
  422. Gui, Add, Button, %k_Position%, /
  423. Gui, Add, Button, x+%k_KeyMargin% w%k_LastShiftWidth% h%k_KeyHeight%, % labels["RShift"]
  424. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  425. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  426. Gui, Add, Button, %k_Position%, % labels["Up"]
  427. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  428. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  429. Gui, Add, Button, %k_Position%, % labels["Numpad1"]
  430. Gui, Add, Button, %k_Position%, % labels["Numpad2"]
  431. Gui, Add, Button, %k_Position%, % labels["Numpad3"]
  432. Gui, Add, Button, %k_Position%, % labels["NumpadEnter"]
  433.  
  434. ;   The last row of keys.
  435. Gui, Add, Button, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["LCtrl"]
  436. Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["LWin"]
  437. Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["LAlt"]
  438. Gui, Add, Button, x+%k_KeyMargin% w%k_SpacebarWidth% h%k_KeyHeight%, Space
  439. Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["RAlt"]
  440. Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["RWin"]
  441. Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["AppsKey"]
  442. Gui, Add, Button, x+%k_KeyMargin% w%k_LastCtrlWidth% h%k_KeyHeight%, % labels["RCtrl"]
  443. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  444. Gui, Add, Button, %k_Position%, % labels["Left"]
  445. Gui, Add, Button, %k_Position%, % labels["Down"]
  446. Gui, Add, Button, %k_Position%, % labels["Right"]
  447. Gui, Add, Progress, %k_Position% Disabled ; Make some space
  448. Gui, Add, Button, %k_Numpad0%, % labels["Numpad0"]
  449. Gui, Add, Button, %k_Position%, % labels["NumpadDot"]
  450.  
  451. ;---- Show the window centered and not active (to avoid changing the current window's focus):
  452. Gui, Show, xCenter NoActivate, Virtual Keyboard View
  453.  
  454. ;   Creates and gives a value to the variable that controls whether the virtual keyboard is
  455. ;   displayed on the screen or not.
  456. k_IsVisible = y
  457.  
  458. ;    Get the window's Width and Height through the GUI's name.
  459. WinGetPos,,, k_WindowWidth, k_WindowHeight, Virtual Keyboard View
  460.  
  461. ;---- Position the keyboard at the bottom of the screen (taking into account
  462. ; the position of the taskbar):
  463. SysGet, k_WorkArea, MonitorWorkArea, %k_Monitor%
  464.  
  465. ; Calculate window's X-position:
  466. k_WindowX = %k_WorkAreaRight%
  467. k_WindowX -= %k_WorkAreaLeft%  ; Now k_WindowX contains the width of this monitor.
  468. k_WindowX -= %k_WindowWidth%
  469. k_WindowX /= 2  ; Calculate position to center it horizontally.
  470. ; The following is done in case the window will be on a non-primary monitor
  471. ; or if the taskbar is anchored on the left side of the screen:
  472. k_WindowX += %k_WorkAreaLeft%
  473.  
  474. ; Calculate window's Y-position:
  475. k_WindowY = %k_WorkAreaBottom%
  476. k_WindowY -= %k_WindowHeight%
  477.  
  478. ;   Move the window to the bottom center position of the monitor.
  479. WinMove, Virtual Keyboard View,, %k_WindowX%, %k_WindowY%
  480.  
  481. ;   Makes the window transparent (the number regulates the transparency).
  482. WinSet, Transparent, 150, Virtual Keyboard View
  483.  
  484. ;---- Set all keys as hotkeys. See www.asciitable.com
  485. k_n = 1
  486. k_ASCII = 45
  487.  
  488. Loop {
  489.     ; Change number into a real character.
  490.     k_char := Chr(k_ASCII)
  491.  
  492.     ; These keys are only accessible using modifier keys, that's why we're escaping them.
  493.     if k_char not in <,>,^,`,
  494.         Hotkey, ~*%k_char%, blinkButton
  495.         ; In the above, the asterisk prefix allows the key to be detected regardless
  496.         ; of whether the user is holding down modifier keys such as Control and Shift.
  497.         ; And without "~" the character wouldn't be shown in the window.
  498.  
  499.     k_ASCII++
  500.  
  501.     ; Stop looping in the last key of the keyboard ("]").
  502. } until (k_ASCII = 94)
  503.  
  504. return ; End of auto-execute section.
  505.  
  506.  
  507. ;---- When a key is pressed by the user, blink the corresponding button on-screen:
  508.  
  509. ;   Fires the corresponding subroutine when we press the specials keys and the normal ones.
  510. ~*`::
  511. ~*Backspace::
  512. ~*Tab::
  513. ~*CapsLock::
  514. ~*'::
  515. ~*Enter::
  516. ~*LShift::
  517. ~*,::
  518. ~*RShift::
  519. ~*LCtrl::  ; Must use Ctrl, not Control, to match button names.
  520. ~*LWin::
  521. ~*LAlt::
  522. ~*Space::
  523. ~*RAlt::
  524. ~*RWin::
  525. ~*AppsKey::
  526. ~*RCtrl::
  527.  
  528. ~*Insert::
  529. ~*Home::
  530. ~*PgUp::
  531. ~*Delete::
  532. ~*End::
  533. ~*PgDn::
  534.  
  535. ~*Up::
  536. ~*Left::
  537. ~*Down::
  538. ~*Right::
  539.  
  540. ~*NumLock::
  541. ~*NumpadDiv::
  542. ~*NumpadMult::
  543. ~*Numpad7::
  544. ~*Numpad8::
  545. ~*Numpad9::
  546. ~*Numpad4::
  547. ~*Numpad5::
  548. ~*Numpad6::
  549. ~*Numpad1::
  550. ~*Numpad2::
  551. ~*Numpad3::
  552. ~*Numpad0::
  553. ~*NumpadDot::
  554.  
  555. ~*NumpadSub::
  556. ~*NumpadAdd::
  557. ~*NumpadEnter::blinkButton()
  558.  
  559.  
  560. ; Show or hide the keyboard if the variable is "y" or "n".
  561. k_ShowHide:
  562.    if k_IsVisible = y
  563.     {
  564.         ; Hide the keyboard gui, change the tray option's name
  565.         ; and update the variable that control the visibility.
  566.         Gui, Cancel
  567.         Menu, Tray, Rename, %k_MenuItemHide%, %k_MenuItemShow%
  568.         k_IsVisible = n
  569.     }
  570.     else
  571.     {
  572.         ; The contrary of the lines above.
  573.         Gui, Show
  574.         Menu, Tray, Rename, %k_MenuItemShow%, %k_MenuItemHide%
  575.         k_IsVisible = y
  576.     }
  577. return
  578.  
  579. ;    Function used to flash the button.
  580. blinkButton()
  581. {
  582.     ; Erase the key ("~*").
  583.     StringReplace, k_ThisHotkey, A_ThisHotkey, ~*
  584.  
  585.     ; Prevents the T and B keys from being confused as Tab and Backspace.
  586.     SetTitleMatchMode, 3
  587.  
  588.     ; Find the variable's index for the control.
  589.     global k_Characters
  590.     index := k_Characters[k_ThisHotkey]
  591.  
  592.     ; Change the color of the corresponding progress bar to red
  593.     ; (beginning of the flashing's process).
  594.     guicontrol, +BackgroundRed, prg%index%
  595.  
  596.     ; Wait for the release of the key.
  597.     KeyWait, %k_ThisHotkey%
  598.  
  599.     ; Return the color of the progress bar to the default (ending of the flashing's process).
  600.     guicontrol, -Background, prg%index%
  601.  
  602.     ; Redraw the button on release (needed because the buttons' names differ from the hotkeys' names).
  603.  
  604.     global labels
  605.     guicontrol, MoveDraw, % (labels[k_ThisHotkey] ? labels[k_ThisHotkey] : k_ThisHotkey)
  606. }
  607.  
  608. ;   Leave the script (with the Escape key,
  609. ;   the window's x button and Exit option in the tray menu icon).
  610. GUIEscape:
  611. GuiClose:
  612. k_MenuExit:
  613.    ExitApp
  614.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement