liuyuqi-dellpc 4 years ago
commit
5860e1756d

+ 230 - 0
KeyboardOnScreen.ahk

@@ -0,0 +1,230 @@
+; On-Screen Keyboard (requires XP/2k/NT) -- by Jon
+; http://www.autohotkey.com
+; This script creates a mock keyboard at the bottom of your screen that shows
+; the keys you are pressing in real time. I made it to help me to learn to
+; touch-type (to get used to not looking at the keyboard).  The size of the
+; on-screen keyboard can be customized at the top of the script. 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 make the entire on-screen keyboard get
+; larger or smaller:
+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 on-screen &keyboard
+k_MenuItemShow = Show on-screen &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%
+k_KeyWidth *= 3
+k_KeyHeight = %k_FontSize%
+k_KeyHeight *= 3
+k_KeyMargin = %k_FontSize%
+k_KeyMargin /= 6
+k_SpacebarWidth = %k_FontSize%
+k_SpacebarWidth *= 25
+k_KeyWidthHalf = %k_KeyWidth%
+k_KeyWidthHalf /= 2
+
+k_KeySize = w%k_KeyWidth% h%k_KeyHeight%
+k_Position = x+%k_KeyMargin% %k_KeySize%
+
+;---- Create a GUI window for the on-screen keyboard:
+Gui, Font, s%k_FontSize% %k_FontStyle%, %k_FontName%
+Gui, -Caption +E0x200 +ToolWindow
+TransColor = F1ECED
+Gui, Color, %TransColor%  ; This color will be made transparent later below.
+
+;---- Add a button for each key. Position the first button with absolute
+; coordinates so that all other buttons can be positioned relative to it:
+Gui, Add, Button, section %k_KeySize% xm+%k_KeyWidth%, 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, %k_Position%, Bk
+
+Gui, Add, Button, xm y+%k_KeyMargin% h%k_KeyHeight%, Tab  ; Auto-width.
+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, %k_Position%, \
+
+Gui, Add, Button, xs+%k_KeyWidthHalf% y+%k_KeyMargin% %k_KeySize%, 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% h%k_KeyHeight%, Enter  ; Auto-width.
+
+; The first button below adds %A_Space% at the end to widen it a little,
+; making the layout of keys next to it more accurately reflect a real keyboard:
+Gui, Add, Button, xm y+%k_KeyMargin% h%k_KeyHeight%, Shift%A_Space%%A_Space%
+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, xm y+%k_KeyMargin% h%k_KeyHeight%, Ctrl  ; Auto-width.
+Gui, Add, Button, h%k_KeyHeight% x+%k_KeyMargin%, Win      ; Auto-width.
+Gui, Add, Button, h%k_KeyHeight% x+%k_KeyMargin%, Alt      ; Auto-width.
+Gui, Add, Button, h%k_KeyHeight% x+%k_KeyMargin% w%k_SpacebarWidth%, Space
+
+
+;---- Show the window:
+Gui, Show
+k_IsVisible = y
+
+WinGet, k_ID, ID, A   ; Get its window ID.
+WinGetPos,,, k_WindowWidth, k_WindowHeight, A
+
+;---- 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%
+
+WinMove, A,, %k_WindowX%, %k_WindowY%
+WinSet, AlwaysOnTop, On, ahk_id %k_ID%
+WinSet, TransColor, %TransColor% 220, ahk_id %k_ID%
+
+
+;---- Set all keys as hotkeys. See www.asciitable.com
+k_n = 1
+k_ASCII = 45
+
+Loop
+{
+	Transform, k_char, Chr, %k_ASCII%
+	StringUpper, k_char, k_char
+	if k_char not in <,>,^,~,,`,
+		Hotkey, ~*%k_char%, k_KeyPress
+		; 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.
+	if k_ASCII = 93
+		break
+	k_ASCII++
+}
+
+return ; End of auto-execute section.
+
+
+;---- When a key is pressed by the user, click the corresponding button on-screen:
+
+~*Backspace::
+ControlClick, Bk, ahk_id %k_ID%, , LEFT, 1, D
+KeyWait, Backspace
+ControlClick, Bk, ahk_id %k_ID%, , LEFT, 1, U
+return
+
+
+; LShift and RShift are used rather than "Shift" because when used as a hotkey,
+; "Shift" would default to firing upon release of the key (in older AHK versions):
+~*LShift::
+~*RShift::
+~*LCtrl::  ; Must use Ctrl not Control to match button names.
+~*RCtrl::
+~*LAlt::
+~*RAlt::
+~*LWin::
+~*RWin::
+StringTrimLeft, k_ThisHotkey, A_ThisHotkey, 3
+ControlClick, %k_ThisHotkey%, ahk_id %k_ID%, , LEFT, 1, D
+KeyWait, %k_ThisHotkey%
+ControlClick, %k_ThisHotkey%, ahk_id %k_ID%, , LEFT, 1, U
+return
+
+
+~*,::
+~*'::
+~*Space::
+~*Enter::
+~*Tab::
+k_KeyPress:
+StringReplace, k_ThisHotkey, A_ThisHotkey, ~
+StringReplace, k_ThisHotkey, k_ThisHotkey, *
+SetTitleMatchMode, 3  ; Prevents the T and B keys from being confused with Tab and Backspace.
+ControlClick, %k_ThisHotkey%, ahk_id %k_ID%, , LEFT, 1, D
+KeyWait, %k_ThisHotkey%
+ControlClick, %k_ThisHotkey%, ahk_id %k_ID%, , LEFT, 1, U
+Return
+
+
+k_ShowHide:
+if k_IsVisible = y
+{
+	Gui, Cancel
+	Menu, Tray, Rename, %k_MenuItemHide%, %k_MenuItemShow%
+	k_IsVisible = n
+}
+else
+{
+	Gui, Show
+	Menu, Tray, Rename, %k_MenuItemShow%, %k_MenuItemHide%
+	k_IsVisible = y
+}
+return
+
+
+GuiClose:
+k_MenuExit:
+ExitApp

+ 11 - 0
README.md

@@ -0,0 +1,11 @@
+## AutoHotKey-Script
+
+自动化按键脚本。
+
+| 脚本                   | 功能                     | 说明 |
+| ---------------------- | ------------------------ | ---- |
+| win+enter_窗体顶置.ahk | 编辑代码时,实现实时预览 |      |
+| 双按Home键熄屏.ahk     | 双按Home键熄屏           |      |
+| 显示按键.ahk           | 录屏讲义                 | 显示很糟糕     |
+| 显示组合键.ahk         | 录屏讲义                         |   修复BUG   |
+| KeyboardOnScreen.ahk  | 屏幕键盘                         | 没啥作用     |

+ 3 - 0
test/1_基础.ahk

@@ -0,0 +1,3 @@
+;               !n=alt + n       Run notepad=打开记事本
+!n::Run notepad
+

+ 14 - 0
test/2_基础send.ahk

@@ -0,0 +1,14 @@
+; ctrl+J 自动输入 My First Script
+^j::
+Send, My First Script
+Return
+
+; 输入 ftw 字符串后,自动替换为 Free the whales
+::ftw::Free the whales
+Return
+
+; 输入 btw 弹框
+::fky::
+   MsgBox You typed "fuck you".
+Return
+

+ 12 - 0
test/3_命令和函数 - Copy.ahk

@@ -0,0 +1,12 @@
+;Command, 参数1, 参数2, 参数3
+
+age=18
+
+^j::
+	MsgBox, Hello
+	MsgBox,%age%
+Return
+
+GetAge(){
+	MsgBox,%age%
+}

+ 7 - 0
test/4_调试.ahk

@@ -0,0 +1,7 @@
+
+
+Hotkey, #c, Display
+
+Display:
+	MsgBox, Hlll
+Return

+ 7 - 0
win+enter_窗体顶置.ahk

@@ -0,0 +1,7 @@
+#space:: 
+    ;将当前激活窗口存入变量w
+    WinGetActiveTitle, w
+    ;对w窗口置顶,Toggle表示在on 与 off 中切换
+    Winset, AlwaysOnTop, Toggle, %w%
+    ;返回执行
+return

+ 17 - 0
双按Home键熄屏.ahk

@@ -0,0 +1,17 @@
+~Home::
+    If Home_Presses > 0{
+        Home_Presses += 1
+        Return
+    }
+    Home_Presses = 1
+    SetTimer, KeyHome, 300
+Return
+
+KeyHome:
+    SetTimer, KeyHome, Off
+    If Home_Presses = 2{
+        Sleep 1000
+        SendMessage, 0x112, 0xF170, 2,, Program Manager
+    }
+    Home_Presses = 0
+Return

+ 304 - 0
显示按键.ahk

@@ -0,0 +1,304 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Config area
+
+; Font settings
+fontSize = 20                   
+fontName = Verdana
+fontStyle = Bold
+
+; The max number of keys that are listed on the screen
+numButtons := 5
+
+; Gui transparecy
+transparent := true
+
+; Distance from the buttons to the edge of the window
+winMargin := 25
+
+; When this is true, old keys are cleared after the speed timer interval
+useSpeedTimer := true
+speedTimer := 1000
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Font metrics functions
+
+FontLen(text)
+{
+    global
+    return StrLen(text) * fontSize + 25
+}
+FontHeight()
+{
+    global
+    return (fontSize * 3)
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Gui Setup
+
+Gui +ToolWindow +AlwaysOnTop
+
+Gui Font, s%fontSize% %fontStyle%, %fontName%
+
+; Create the buttons with 0 width
+Loop % numButtons 
+{
+    height := FontHeight()
+    if (A_Index == 1)
+        Gui Add, Button, w0 h%height% X%winMargin% ym
+    else
+        Gui Add, Button, w0 h%height% ym
+}
+
+; Show the gui with a default 200 width
+Gui Show, w200, Screenkey.ahk  
+
+; Save the window id
+WinGet k_ID, ID, A   
+
+If (transparent)
+{
+    TransColor = F1ECED
+    Gui Color, %TransColor%
+    WinSet TransColor, %TransColor% 220, ahk_id %k_ID%
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Hotkeys
+
+CaptureKeyboardInputs()
+{
+    global
+    static keys
+    keys=Space,Enter,Tab,Esc,BackSpace,Del,Ins,Home,End,PgDn,PgUp,Up,Down,Left,Right,CtrlBreak,ScrollLock,PrintScreen,CapsLock
+,Pause,AppsKey,NumLock,Numpad0,Numpad1,Numpad2,Numpad3,Numpad4,Numpad5,Numpad6,Numpad7,Numpad8,Numpad9,NumpadDot
+,NumpadDiv,NumpadMult,NumpadAdd,NumpadSub,NumpadEnter,NumpadIns,NumpadEnd,NumpadDown,NumpadPgDn,NumpadLeft,NumpadClear
+,NumpadRight,NumpadHome,NumpadUp,NumpadPgUp,NumpadDel,Media_Next,Media_Play_Pause,Media_Prev,Media_Stop,Volume_Down,Volume_Up
+,Volume_Mute,Browser_Back,Browser_Favorites,Browser_Home,Browser_Refresh,Browser_Search,Browser_Stop,Launch_App1,Launch_App2
+,Launch_Mail,Launch_Media,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12,F13,F14,F15,F16,F17,F18,F19,F20,F21,F22
+,1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
+,[,],',=,\,/
+
+    Loop Parse, keys, `,
+        Hotkey, ~*%A_LoopField%, KeyHandleLabel, UseErrorLevel
+    return
+
+    KeyHandleLabel:
+        KeyHandle()
+    return
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Hotkey handles
+
+current := 1
+clear := false
+
+KeyHandle()
+{
+    global
+
+    keyname := RegExReplace(A_ThisHotKey, "~\*", "")
+
+    dispkey := Up(keyname)
+
+    mods := ModifierNames(keyname)
+
+    dispkey := mods . dispkey
+
+    len := FontLen(dispkey)
+
+    ; resize the button with what needs to be displayed
+    GuiControl Move, Button%current%, w%len%
+    ControlSetText Button%current%, %dispkey%, ahk_id %k_ID%
+
+    if (current == 1 && clear)
+    {
+        ; Clear the rest of buttons - resize them to 0 width
+        Loop % numButtons - 1
+        {
+            curr := A_Index + 1
+            GuiControl Move, Button%curr%, w0 
+        }
+    }
+
+    ; move to the next button
+    current++
+
+    if (current > numButtons)
+    {
+        current := 1
+        clear := true
+    }
+    else 
+    {
+        ; reposition the remaining buttons
+        Loop
+        {
+            if (A_Index < current)
+                continue
+
+            prev := A_Index - 1
+            GuiControlGet Button%prev%, Pos
+            newX := % Button%prev%X + Button%prev%W 
+            GuiControl Move, Button%A_Index%, X%newX% 
+
+            if (A_Index >= numButtons)
+                break
+        }
+    }
+   
+    ; calculate the new total width of the window 
+    winWidth := 0
+    Loop % numButtons
+    {
+        GuiControlGet Button%A_Index%, Pos
+        w := Button%A_Index%W
+        winWidth := w + winWidth
+    }
+
+    WinMove ahk_id %k_ID%,,,, winWidth + 2 * winMargin
+
+    ; install the speed timer that clears all the buttons when the next key is hit
+    if (useSpeedTimer)
+    {
+        SetTimer HandleSpeedType, %speedTimer%
+    }
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Helper functions
+
+IsUpperCase(key)
+{
+    caps := GetKeyState("CapsLock", "T")
+    shift := GetKeyState("Shift", "P")
+
+    if (caps && !shift || !caps && shift)
+    {
+        return true
+    }
+    
+    return false
+}
+
+ModifierNames(key)
+{
+    mods := ""
+    shift := GetKeyState("Shift", "P")
+    ctrl := GetKeyState("Ctrl", "P")
+    alt := GetKeyState("Alt", "P")
+    win := GetKeyState("LWin", "P")
+
+    special := "[,],',=,\,/,;,``,."
+
+    if (StrLen(key) == 1)
+    {
+        if (key >= "0" && key <="9")
+            shift := false
+        if (key >= "a" && key <="z")
+            shift := false
+        if (key >= "A" && key <="Z")
+            shift := false
+        if (Instr(special, key))
+            shift := false
+    }
+    
+    if (shift)
+        mods := mods . "Shift+"
+    if (ctrl)
+        mods := mods . "Ctrl+"
+    if (alt)
+        mods := mods . "Alt+"
+    if (win)
+        mods := mods . "Win+"
+        
+    return (mods)
+}
+
+Up(inkey)
+{   
+    outkey := ""
+
+    if (IsUpperCase(inkey) && StrLen(inkey) == 1 && inkey >= "a" && inkey <= "z")
+    {
+        StringUpper outkey, inkey 
+        return outkey
+    }
+    
+    shift := GetKeyState("Shift", "P")
+
+    if (shift)
+    {
+        if (inkey == "1") 
+            return "!"
+        if (inkey == "2")
+            return "@"
+        if (inkey == "3")
+            return "#"
+        if (inkey == "4")
+            return "$"
+        if (inkey == "5")
+            return "%"
+        if (inkey == "6")
+            return "^"
+        if (inkey == "7")
+            return "&&"
+        if (inkey == "8")
+            return "*"
+        if (inkey == "9")
+            return "("
+        if (inkey == "0")
+            return ")"
+        if (inkey == "-")
+            return "_"
+        if (inkey == "=")
+            return "+"
+        if (inkey == "[")
+            return "{"
+        if (inkey == "]")
+            return "}"
+        if (inkey == "\")
+            return "|"
+        if (inkey == ",")
+            return "<"
+        if (inkey == ".")
+            return ">"
+        if (inkey == "/")
+            return "?"
+        if (inkey == "``")
+            return "~"
+        if (inkey == ";")
+            return ":"
+        if (inkey == "'")
+        {
+            quote = "
+            return quote
+        }
+    }
+
+    return inkey
+}
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; Install hotkeys
+
+CaptureKeyboardInputs()
+
+; special handling for special characters
+~*;::
+~*,::
+~*.::
+~*`::
+    KeyHandle()
+return
+
+HandleSpeedType:
+    current := 1
+    clear := true
+    SetTimer HandleSpeedType, Off
+return
+
+
+GuiClose:
+ExitApp

+ 92 - 0
显示组合键.ahk

@@ -0,0 +1,92 @@
+#SingleInstance force
+#NoEnv
+SetBatchLines, -1
+
+transN := 200	; 透明度
+
+
+; #################################
+;		GUI
+; #################################
+;
+Gui, +AlwaysOnTop +ToolWindow -SysMenu -Caption +LastFound
+Gui, Margin, 0, 0
+WinSet, ExStyle, +0x20		 ; 鼠标穿透
+WinSet, Transparent, %transN%
+Gui, Color, Black
+Gui, Font, cWhite s50 bold, Arial
+Gui, Add, Text, vHotkeyText Center y20
+
+
+; #################################
+;		绑定按键
+; #################################
+;重复95次,A_Index表示第i次,默认0。Chr(32)表示空格
+Loop, 95
+	Hotkey, % "~*" Chr(A_Index + 32), Display
+
+Loop, 24 ; F1-F24
+	Hotkey, % "~*F" A_Index, Display
+
+Loop, 10 ; Numpad0 - Numpad9
+	Hotkey, % "~*Numpad" A_Index - 1, Display
+
+Otherkeys := "NumpadDiv|NumpadMult|NumpadAdd|NumpadSub|NumpadEnter|Tab|Enter|Esc|BackSpace|Del|Insert|Home|End|PgUp|PgDn|Up|Down|Left|Right|ScrollLock|CapsLock|NumLock|Pause"
+Loop, parse, Otherkeys, |
+	Hotkey, % "~*" A_LoopField, Display
+
+Return
+
+
+; #################################
+;		显示按键
+; #################################
+;
+Display:
+	If A_ThisHotkey =
+		Return
+
+	mods := "Ctrl|Shift|Alt|LWin|RWin"
+	prefix =
+
+	Loop, Parse, mods, |
+		if GetKeyState(A_LoopField)
+			prefix := prefix A_LoopField " + "
+
+	if !prefix		; 如果没有组合键则不显示
+		return
+
+	key := SubStr(A_ThisHotkey, 3)
+	if (key = " ")
+		key := "Space"
+
+	ShowHotkey(prefix key)
+	FadeOut()
+Return
+
+
+; ===================================================================================
+ShowHotkey(Hotkey)
+{
+	GuiControl,, HotkeyText, %Hotkey%
+
+	WinGetPos, ActWin_X, ActWin_Y, ActWin_W, ActWin_H, A
+	text_w := ActWin_W, gui_y := (ActWin_Y+ActWin_H) - 115 - 50
+	GuiControl, Move, HotkeyText, w%text_w% center
+
+	Gui, Show, NoActivate x%ActWin_X% y%gui_y% h115 w%text_w%
+}
+
+FadeOut(sleep = 1000)
+{
+	global transN
+
+	Sleep, %Sleep%
+	Gui, +LastFound
+
+	Loop, % transN
+		WinSet, Transparent, % (A_Index - transN - 1) * -1
+
+	Gui, Hide
+	WinSet, Transparent, % transN
+}