Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; 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)
- ; https://autohotkey.com/board/topic/94703-another-approach-to-a-virtual-keyboard/
- ; Made from Jon's original code (http://www.autohotkey.com) with blinking by Lehnemann.
- ;
- ; The main objective of the program remains the same:
- ; To create a virtual visualization of the keyboard and to show which key is being pressed.
- ;
- ; The code has small updates and the main change was the way the virtual keyboard
- ; indicates which key was pressed. The original method, the easiest, used left-clicks
- ; on the virtual keyboard buttons to indicate which key was pressed. What I used is
- ; based on the use of two layers of controls (one with progress bars and one with
- ; buttons) to flash the button being pressed.
- ;
- ; With the F2 hotkey, I show another approach to the flashing of a control.
- ;
- ; In the same way, the size of the on-screen keyboard can be customized
- ; at the top of the script (through the font size). Also, you can
- ; double-click the tray icon to show or hide the keyboard.
- ;---- Configuration Section: Customize the size of the on-screen keyboard and
- ; other options here.
- ; Changing this font size will resize the keyboard:
- k_FontSize = 10
- k_FontName = Verdana ; This can be blank to use the system's default font.
- k_FontStyle = Bold ; Example of an alternative: Italic Underline
- ; Names for the tray menu items:
- k_MenuItemHide := "Hide keyboard"
- k_MenuItemShow := "Show keyboard"
- ; To have the keyboard appear on a monitor other than the primary, specify
- ; a number such as 2 for the following variable. Leave it blank to use
- ; the primary:
- k_Monitor =
- ;---- End of configuration section. Don't change anything below this point
- ; unless you want to alter the basic nature of the script.
- ;---- Alter the tray icon menu:
- Menu, Tray, Add, %k_MenuItemHide%, k_ShowHide
- Menu, Tray, Add, &Exit, k_MenuExit
- Menu, Tray, Default, %k_MenuItemHide%
- Menu, Tray, NoStandard
- ;---- Calculate object dimensions based on chosen font size:
- k_KeyWidth := k_FontSize * 3
- k_KeyHeight := k_FontSize * 3
- k_KeyWidth0 := k_KeyWidth * 2
- ; Spacing to be used between the keys.
- k_KeyMargin := k_FontSize // 6
- ; The total width of the keyboard to be assembled in terms of the keys and the spacing between them.
- width := 15 * k_KeyWidth + 14 * k_KeyMargin
- ; Special keys. Along with the size of the default key, they help define the virtual keyboard
- ; (depends on the type of keyboard).
- ; Notice that both the initial and final keys of each row are important to build the virtual keyboard.
- k_KeyWidthHalf := k_KeyWidth / 2
- k_TabW := k_FontSize * 4
- k_CapsW := k_KeyWidth + k_KeyMargin + k_KeyWidthHalf
- k_ShiftW := 2 * k_KeyWidth + k_KeyMargin
- k_SpacebarWidth := k_FontSize * 17
- k_LastKeyWidth := width - ( k_TabW + 12 * k_KeyWidth + 13 * k_KeyMargin )
- k_EnterWidth := width - ( k_CapsW + 11 * k_KeyWidth + 12 * k_KeyMargin )
- k_LastShiftWidth := width - ( k_ShiftW + 10 * k_KeyWidth + 11 * k_KeyMargin )
- k_LastCtrlWidth := width - ( 6 * k_TabW + k_SpacebarWidth + 7 * k_KeyMargin )
- ; Only a facilitator for creating GUI.
- k_KeySize = w%k_KeyWidth% h%k_KeyHeight%
- k_KeySize0 = w%k_KeyWidth0% h%k_KeyHeight%
- k_Position = x+%k_KeyMargin% %k_KeySize%
- k_Numpad0 = x+%k_KeyMargin% %k_KeySize0%
- ; This table is used to relate the hotkeys pressed with their progress bars,
- ; to flash them on the ANSI-style keyboard.
- k_Characters := {"" : ""
- , "``" : 1
- , 1 : 2
- , 2 : 3
- , 3 : 4
- , 4 : 5
- , 5 : 6
- , 6 : 7
- , 7 : 8
- , 8 : 9
- , 9 : 10
- , 0 : 11
- , "-" : 12
- , "=" : 13
- , "Backspace" : 14
- , "Tab" : 15
- , "Q" : 16
- , "W" : 17
- , "E" : 18
- , "R" : 19
- , "T" : 20
- , "Y" : 21
- , "U" : 22
- , "I" : 23
- , "O" : 24
- , "P" : 25
- , "[" : 26
- , "]" : 27
- , "\" : 28
- , "CapsLock" : 29
- , "A" : 30
- , "S" : 31
- , "D" : 32
- , "F" : 33
- , "G" : 34
- , "H" : 35
- , "J" : 36
- , "K" : 37
- , "L" : 38
- , ";" : 39
- , "'" : 40
- , "Enter" : 41
- , "LShift" : 42
- , "Z" : 43
- , "X" : 44
- , "C" : 45
- , "V" : 46
- , "B" : 47
- , "N" : 48
- , "M" : 49
- , "," : 50
- , "." : 51
- , "/" : 52
- , "RShift" : 53
- , "LCtrl" : 54
- , "LWin" : 55
- , "LAlt" : 56
- , "Space" : 57
- , "RAlt" : 58
- , "RWin" : 59
- , "AppsKey" : 60
- , "RCtrl" : 61
- , "Insert" : 62
- , "Home" : 63
- , "PgUp" : 64
- , "Delete" : 65
- , "End" : 66
- , "PgDn" : 67
- , "Up" : 68
- , "Left" : 69
- , "Down" : 70
- , "Right" : 71
- , "NumLock" : 72
- , "NumpadDiv" : 73
- , "NumpadMult" : 74
- , "NumpadSub" : 75
- , "Numpad7" : 76
- , "Numpad8" : 77
- , "Numpad9" : 78
- , "NumpadAdd" : 79
- , "Numpad4" : 80
- , "Numpad5" : 81
- , "Numpad6" : 82
- , "Numpad1" : 83
- , "Numpad2" : 84
- , "Numpad3" : 85
- , "NumpadEnter" : 86
- , "Numpad0" : 87
- , "NumpadDot" : 88 }
- labels := { "" : ""
- , "AppsKey" : "App"
- , "BackSpace" : "🡄"
- , "CapsLock" : "Caps"
- , "Delete" : "Del"
- , "Down" : "⮟"
- , "End" : "⇲"
- , "Home" : "⇱"
- , "Insert" : "Ins"
- , "LAlt" : "Alt"
- , "LCtrl" : "lCtrl"
- , "Left" : "⮜"
- , "LShift" : "lShift"
- , "LWin" : "lWin"
- , "NumLock" : "🔒"
- , "Numpad0" : "𝟎"
- , "Numpad1" : "𝟏"
- , "Numpad2" : "𝟐"
- , "Numpad3" : "𝟑"
- , "Numpad4" : "𝟒"
- , "Numpad5" : "𝟓"
- , "Numpad6" : "𝟔"
- , "Numpad7" : "𝟕"
- , "Numpad8" : "𝟖"
- , "Numpad9" : "𝟗"
- , "NumpadAdd" : "+"
- , "NumpadDiv" : "/"
- , "NumpadDot" : "․"
- , "NumpadEnter": "Ent"
- , "NumpadMult" : "*"
- , "NumpadSub" : "–"
- , "PgDn" : "PD"
- , "PgUp" : "PU"
- , "RAlt" : "rAlt"
- , "RCtrl" : "rCtrl"
- , "Right" : "⮞"
- , "RShift" : "rShift"
- , "RWin" : "rWin"
- , "Tab" : "⭾"
- , "Up" : "⮝" }
- ;---- Create a GUI window for the on-screen keyboard:
- Gui, Font, s%k_FontSize% %k_FontStyle%, %k_FontName%
- Gui, -Caption +AlwaysOnTop -MaximizeBox +ToolWindow
- ; About keyboards: The tab and ctrl have the same size, all the buttons on the far right fit to the size of the
- ; keyboard (dictated by the first line), the left shift has the same size of the backspace (Western keyboards),
- ; the window size is given by x1 + 15 * + 14 * wKey kMargin and y1 + 5 * 4 * + hKey kMargin (where x1 and y1 are
- ; the coordinates of the first key on the top left of the keyboard).
- ; We created two layers of controls, one below the other. The bottom layer containing the progresses bar that
- ; will be used to generate the blinking effect. And the top layer represent the buttons themselves.
- ; The first row of the virtual keyboard.
- Gui, Add, Progress, section xm ym %k_KeySize% Disabled vprg1
- Gui, Add, Progress, %k_Position% Disabled vprg2
- Gui, Add, Progress, %k_Position% Disabled vprg3
- Gui, Add, Progress, %k_Position% Disabled vprg4
- Gui, Add, Progress, %k_Position% Disabled vprg5
- Gui, Add, Progress, %k_Position% Disabled vprg6
- Gui, Add, Progress, %k_Position% Disabled vprg7
- Gui, Add, Progress, %k_Position% Disabled vprg8
- Gui, Add, Progress, %k_Position% Disabled vprg9
- Gui, Add, Progress, %k_Position% Disabled vprg10
- Gui, Add, Progress, %k_Position% Disabled vprg11
- Gui, Add, Progress, %k_Position% Disabled vprg12
- Gui, Add, Progress, %k_Position% Disabled vprg13
- Gui, Add, Progress, x+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight% Disabled vprg14
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled vprg62 ; Insert
- Gui, Add, Progress, %k_Position% Disabled vprg63 ; Home
- Gui, Add, Progress, %k_Position% Disabled vprg64 ; PgUp
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled vprg72 ; NumLock
- Gui, Add, Progress, %k_Position% Disabled vprg73 ; NumpadDiv
- Gui, Add, Progress, %k_Position% Disabled vprg74 ; NumpadMult
- Gui, Add, Progress, %k_Position% Disabled vprg75 ; NumpadSub
- ; The second row.
- Gui, Add, Progress, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg15
- Gui, Add, Progress, %k_Position% Disabled vprg16
- Gui, Add, Progress, %k_Position% Disabled vprg17
- Gui, Add, Progress, %k_Position% Disabled vprg18
- Gui, Add, Progress, %k_Position% Disabled vprg19
- Gui, Add, Progress, %k_Position% Disabled vprg20
- Gui, Add, Progress, %k_Position% Disabled vprg21
- Gui, Add, Progress, %k_Position% Disabled vprg22
- Gui, Add, Progress, %k_Position% Disabled vprg23
- Gui, Add, Progress, %k_Position% Disabled vprg24
- Gui, Add, Progress, %k_Position% Disabled vprg25
- Gui, Add, Progress, %k_Position% Disabled vprg26
- Gui, Add, Progress, %k_Position% Disabled vprg27
- Gui, Add, Progress, x+%k_KeyMargin% w%k_LastKeyWidth% h%k_KeyHeight% Disabled vprg28
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled vprg65 ; Delete
- Gui, Add, Progress, %k_Position% Disabled vprg66 ; End
- Gui, Add, Progress, %k_Position% Disabled vprg67 ; PgDn
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled vprg76 ; Numpad7
- Gui, Add, Progress, %k_Position% Disabled vprg77 ; Numpad8
- Gui, Add, Progress, %k_Position% Disabled vprg78 ; Numpad9
- Gui, Add, Progress, %k_Position% Disabled vprg79 ; NumpadAdd
- ; The third row.
- Gui, Add, Progress, xm y+%k_KeyMargin% w%k_CapsW% h%k_KeyHeight% Disabled vprg29
- Gui, Add, Progress, %k_Position% Disabled vprg30
- Gui, Add, Progress, %k_Position% Disabled vprg31
- Gui, Add, Progress, %k_Position% Disabled vprg32
- Gui, Add, Progress, %k_Position% Disabled vprg33
- Gui, Add, Progress, %k_Position% Disabled vprg34
- Gui, Add, Progress, %k_Position% Disabled vprg35
- Gui, Add, Progress, %k_Position% Disabled vprg36
- Gui, Add, Progress, %k_Position% Disabled vprg37
- Gui, Add, Progress, %k_Position% Disabled vprg38
- Gui, Add, Progress, %k_Position% Disabled vprg39
- Gui, Add, Progress, %k_Position% Disabled vprg40
- Gui, Add, Progress, x+%k_KeyMargin% w%k_EnterWidth% h%k_KeyHeight% Disabled vprg41
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled vprg80 ; Numpad4
- Gui, Add, Progress, %k_Position% Disabled vprg81 ; Numpad5
- Gui, Add, Progress, %k_Position% Disabled vprg82 ; Numpad6
- ; The fourth row.
- Gui, Add, Progress, xm y+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight% Disabled vprg42
- Gui, Add, Progress, %k_Position% Disabled vprg43
- Gui, Add, Progress, %k_Position% Disabled vprg44
- Gui, Add, Progress, %k_Position% Disabled vprg45
- Gui, Add, Progress, %k_Position% Disabled vprg46
- Gui, Add, Progress, %k_Position% Disabled vprg47
- Gui, Add, Progress, %k_Position% Disabled vprg48
- Gui, Add, Progress, %k_Position% Disabled vprg49
- Gui, Add, Progress, %k_Position% Disabled vprg50
- Gui, Add, Progress, %k_Position% Disabled vprg51
- Gui, Add, Progress, %k_Position% Disabled vprg52
- Gui, Add, Progress, x+%k_KeyMargin% w%k_LastShiftWidth% h%k_KeyHeight% Disabled vprg53
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled vprg68 ; Up
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled vprg83 ; Numpad1
- Gui, Add, Progress, %k_Position% Disabled vprg84 ; Numpad2
- Gui, Add, Progress, %k_Position% Disabled vprg85 ; Numpad3
- Gui, Add, Progress, %k_Position% Disabled vprg86 ; NumpadEnter
- ; The last row of keys.
- Gui, Add, Progress, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg54
- Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg55
- Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg56
- Gui, Add, Progress, x+%k_KeyMargin% w%k_SpacebarWidth% h%k_KeyHeight% Disabled vprg57
- Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg58
- Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg59
- Gui, Add, Progress, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight% Disabled vprg60
- Gui, Add, Progress, x+%lastPos% w%k_LastCtrlWidth% h%k_KeyHeight% Disabled vprg61
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled vprg69 ; Left
- Gui, Add, Progress, %k_Position% Disabled vprg70 ; Down
- Gui, Add, Progress, %k_Position% Disabled vprg71 ; Right
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Numpad0% Disabled vprg87 ; Numpad0
- Gui, Add, Progress, %k_Position% Disabled vprg88 ; NumpadDot
- ;---- Add a button for each key. Position the first button with absolute
- ; coordinates so that all other buttons can be positioned relative to it:
- ; The first row of the virtual keyboard.
- Gui, Add, Button, section xm ym %k_KeySize%, ``
- Gui, Add, Button, %k_Position%, 1
- Gui, Add, Button, %k_Position%, 2
- Gui, Add, Button, %k_Position%, 3
- Gui, Add, Button, %k_Position%, 4
- Gui, Add, Button, %k_Position%, 5
- Gui, Add, Button, %k_Position%, 6
- Gui, Add, Button, %k_Position%, 7
- Gui, Add, Button, %k_Position%, 8
- Gui, Add, Button, %k_Position%, 9
- Gui, Add, Button, %k_Position%, 0
- Gui, Add, Button, %k_Position%, -
- Gui, Add, Button, %k_Position%, =
- Gui, Add, Button, x+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight%, % labels["Backspace"]
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Button, %k_Position%, Ins
- Gui, Add, Button, %k_Position%, % labels["Home"]
- Gui, Add, Button, %k_Position%, % labels["PgUp"]
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Button, %k_Position%, % labels["NumLock"]
- Gui, Add, Button, %k_Position%, /
- Gui, Add, Button, %k_Position%, *
- Gui, Add, Button, %k_Position%, % labels["NumpadSub"]
- ; The second row.
- Gui, Add, Button, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["Tab"]
- Gui, Add, Button, %k_Position%, Q
- Gui, Add, Button, %k_Position%, W
- Gui, Add, Button, %k_Position%, E
- Gui, Add, Button, %k_Position%, R
- Gui, Add, Button, %k_Position%, T
- Gui, Add, Button, %k_Position%, Y
- Gui, Add, Button, %k_Position%, U
- Gui, Add, Button, %k_Position%, I
- Gui, Add, Button, %k_Position%, O
- Gui, Add, Button, %k_Position%, P
- Gui, Add, Button, %k_Position%, [
- Gui, Add, Button, %k_Position%, ]
- Gui, Add, Button, x+%k_KeyMargin% w%k_LastKeyWidth% h%k_KeyHeight%, \
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Button, %k_Position%, Del
- Gui, Add, Button, %k_Position%, % labels["End"]
- Gui, Add, Button, %k_Position%, % labels["PgDn"]
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Button, %k_Position%, % labels["Numpad7"]
- Gui, Add, Button, %k_Position%, % labels["Numpad8"]
- Gui, Add, Button, %k_Position%, % labels["Numpad9"]
- Gui, Add, Button, %k_Position%, +
- ; The third row.
- Gui, Add, Button, xm y+%k_KeyMargin% w%k_CapsW% h%k_KeyHeight%, % labels["CapsLock"]
- Gui, Add, Button, %k_Position%, A
- Gui, Add, Button, %k_Position%, S
- Gui, Add, Button, %k_Position%, D
- Gui, Add, Button, %k_Position%, F
- Gui, Add, Button, %k_Position%, G
- Gui, Add, Button, %k_Position%, H
- Gui, Add, Button, %k_Position%, J
- Gui, Add, Button, %k_Position%, K
- Gui, Add, Button, %k_Position%, L
- Gui, Add, Button, %k_Position%, `;
- Gui, Add, Button, %k_Position%, '
- Gui, Add, Button, x+%k_KeyMargin% w%k_EnterWidth% h%k_KeyHeight%, Enter
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Button, %k_Position%, % labels["Numpad4"]
- Gui, Add, Button, %k_Position%, % labels["Numpad5"]
- Gui, Add, Button, %k_Position%, % labels["Numpad6"]
- ; The fourth row.
- Gui, Add, Button, xm y+%k_KeyMargin% w%k_ShiftW% h%k_KeyHeight%, % labels["LShift"]
- Gui, Add, Button, %k_Position%, Z
- Gui, Add, Button, %k_Position%, X
- Gui, Add, Button, %k_Position%, C
- Gui, Add, Button, %k_Position%, V
- Gui, Add, Button, %k_Position%, B
- Gui, Add, Button, %k_Position%, N
- Gui, Add, Button, %k_Position%, M
- Gui, Add, Button, %k_Position%, `,
- Gui, Add, Button, %k_Position%, .
- Gui, Add, Button, %k_Position%, /
- Gui, Add, Button, x+%k_KeyMargin% w%k_LastShiftWidth% h%k_KeyHeight%, % labels["RShift"]
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Button, %k_Position%, % labels["Up"]
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Button, %k_Position%, % labels["Numpad1"]
- Gui, Add, Button, %k_Position%, % labels["Numpad2"]
- Gui, Add, Button, %k_Position%, % labels["Numpad3"]
- Gui, Add, Button, %k_Position%, % labels["NumpadEnter"]
- ; The last row of keys.
- Gui, Add, Button, xm y+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["LCtrl"]
- Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["LWin"]
- Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["LAlt"]
- Gui, Add, Button, x+%k_KeyMargin% w%k_SpacebarWidth% h%k_KeyHeight%, Space
- Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["RAlt"]
- Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["RWin"]
- Gui, Add, Button, x+%k_KeyMargin% w%k_TabW% h%k_KeyHeight%, % labels["AppsKey"]
- Gui, Add, Button, x+%k_KeyMargin% w%k_LastCtrlWidth% h%k_KeyHeight%, % labels["RCtrl"]
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Button, %k_Position%, % labels["Left"]
- Gui, Add, Button, %k_Position%, % labels["Down"]
- Gui, Add, Button, %k_Position%, % labels["Right"]
- Gui, Add, Progress, %k_Position% Disabled ; Make some space
- Gui, Add, Button, %k_Numpad0%, % labels["Numpad0"]
- Gui, Add, Button, %k_Position%, % labels["NumpadDot"]
- ;---- Show the window centered and not active (to avoid changing the current window's focus):
- Gui, Show, xCenter NoActivate, Virtual Keyboard View
- ; Creates and gives a value to the variable that controls whether the virtual keyboard is
- ; displayed on the screen or not.
- k_IsVisible = y
- ; Get the window's Width and Height through the GUI's name.
- WinGetPos,,, k_WindowWidth, k_WindowHeight, Virtual Keyboard View
- ;---- Position the keyboard at the bottom of the screen (taking into account
- ; the position of the taskbar):
- SysGet, k_WorkArea, MonitorWorkArea, %k_Monitor%
- ; Calculate window's X-position:
- k_WindowX = %k_WorkAreaRight%
- k_WindowX -= %k_WorkAreaLeft% ; Now k_WindowX contains the width of this monitor.
- k_WindowX -= %k_WindowWidth%
- k_WindowX /= 2 ; Calculate position to center it horizontally.
- ; The following is done in case the window will be on a non-primary monitor
- ; or if the taskbar is anchored on the left side of the screen:
- k_WindowX += %k_WorkAreaLeft%
- ; Calculate window's Y-position:
- k_WindowY = %k_WorkAreaBottom%
- k_WindowY -= %k_WindowHeight%
- ; Move the window to the bottom center position of the monitor.
- WinMove, Virtual Keyboard View,, %k_WindowX%, %k_WindowY%
- ; Makes the window transparent (the number regulates the transparency).
- WinSet, Transparent, 150, Virtual Keyboard View
- ;---- Set all keys as hotkeys. See www.asciitable.com
- k_n = 1
- k_ASCII = 45
- Loop {
- ; Change number into a real character.
- k_char := Chr(k_ASCII)
- ; These keys are only accessible using modifier keys, that's why we're escaping them.
- if k_char not in <,>,^,`,
- Hotkey, ~*%k_char%, blinkButton
- ; In the above, the asterisk prefix allows the key to be detected regardless
- ; of whether the user is holding down modifier keys such as Control and Shift.
- ; And without "~" the character wouldn't be shown in the window.
- k_ASCII++
- ; Stop looping in the last key of the keyboard ("]").
- } until (k_ASCII = 94)
- return ; End of auto-execute section.
- ;---- When a key is pressed by the user, blink the corresponding button on-screen:
- ; Fires the corresponding subroutine when we press the specials keys and the normal ones.
- ~*`::
- ~*Backspace::
- ~*Tab::
- ~*CapsLock::
- ~*'::
- ~*Enter::
- ~*LShift::
- ~*,::
- ~*RShift::
- ~*LCtrl:: ; Must use Ctrl, not Control, to match button names.
- ~*LWin::
- ~*LAlt::
- ~*Space::
- ~*RAlt::
- ~*RWin::
- ~*AppsKey::
- ~*RCtrl::
- ~*Insert::
- ~*Home::
- ~*PgUp::
- ~*Delete::
- ~*End::
- ~*PgDn::
- ~*Up::
- ~*Left::
- ~*Down::
- ~*Right::
- ~*NumLock::
- ~*NumpadDiv::
- ~*NumpadMult::
- ~*Numpad7::
- ~*Numpad8::
- ~*Numpad9::
- ~*Numpad4::
- ~*Numpad5::
- ~*Numpad6::
- ~*Numpad1::
- ~*Numpad2::
- ~*Numpad3::
- ~*Numpad0::
- ~*NumpadDot::
- ~*NumpadSub::
- ~*NumpadAdd::
- ~*NumpadEnter::blinkButton()
- ; Show or hide the keyboard if the variable is "y" or "n".
- k_ShowHide:
- if k_IsVisible = y
- {
- ; Hide the keyboard gui, change the tray option's name
- ; and update the variable that control the visibility.
- Gui, Cancel
- Menu, Tray, Rename, %k_MenuItemHide%, %k_MenuItemShow%
- k_IsVisible = n
- }
- else
- {
- ; The contrary of the lines above.
- Gui, Show
- Menu, Tray, Rename, %k_MenuItemShow%, %k_MenuItemHide%
- k_IsVisible = y
- }
- return
- ; Function used to flash the button.
- blinkButton()
- {
- ; Erase the key ("~*").
- StringReplace, k_ThisHotkey, A_ThisHotkey, ~*
- ; Prevents the T and B keys from being confused as Tab and Backspace.
- SetTitleMatchMode, 3
- ; Find the variable's index for the control.
- global k_Characters
- index := k_Characters[k_ThisHotkey]
- ; Change the color of the corresponding progress bar to red
- ; (beginning of the flashing's process).
- guicontrol, +BackgroundRed, prg%index%
- ; Wait for the release of the key.
- KeyWait, %k_ThisHotkey%
- ; Return the color of the progress bar to the default (ending of the flashing's process).
- guicontrol, -Background, prg%index%
- ; Redraw the button on release (needed because the buttons' names differ from the hotkeys' names).
- global labels
- guicontrol, MoveDraw, % (labels[k_ThisHotkey] ? labels[k_ThisHotkey] : k_ThisHotkey)
- }
- ; Leave the script (with the Escape key,
- ; the window's x button and Exit option in the tray menu icon).
- GUIEscape:
- GuiClose:
- k_MenuExit:
- ExitApp
Add Comment
Please, Sign In to add comment