显示组合键.ahk 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #SingleInstance force
  2. #NoEnv
  3. SetBatchLines, -1
  4. transN := 200 ; 透明度
  5. ; #################################
  6. ; GUI
  7. ; #################################
  8. ;
  9. Gui, +AlwaysOnTop +ToolWindow -SysMenu -Caption +LastFound
  10. Gui, Margin, 0, 0
  11. WinSet, ExStyle, +0x20 ; 鼠标穿透
  12. WinSet, Transparent, %transN%
  13. Gui, Color, Black
  14. Gui, Font, cWhite s50 bold, Arial
  15. Gui, Add, Text, vHotkeyText Center y20
  16. ; #################################
  17. ; 绑定按键
  18. ; #################################
  19. ;重复95次,A_Index表示第i次,默认0。Chr(32)表示空格
  20. Loop, 95
  21. Hotkey, % "~*" Chr(A_Index + 32), Display
  22. Loop, 24 ; F1-F24
  23. Hotkey, % "~*F" A_Index, Display
  24. Loop, 10 ; Numpad0 - Numpad9
  25. Hotkey, % "~*Numpad" A_Index - 1, Display
  26. Otherkeys := "NumpadDiv|NumpadMult|NumpadAdd|NumpadSub|NumpadEnter|Tab|Enter|Esc|BackSpace|Del|Insert|Home|End|PgUp|PgDn|Up|Down|Left|Right|ScrollLock|CapsLock|NumLock|Pause"
  27. Loop, parse, Otherkeys, |
  28. Hotkey, % "~*" A_LoopField, Display
  29. Return
  30. ; #################################
  31. ; 显示按键
  32. ; #################################
  33. ;
  34. Display:
  35. If A_ThisHotkey =
  36. Return
  37. mods := "Ctrl|Shift|Alt|LWin|RWin"
  38. prefix =
  39. Loop, Parse, mods, |
  40. if GetKeyState(A_LoopField)
  41. prefix := prefix A_LoopField " + "
  42. if !prefix ; 如果没有组合键则不显示
  43. return
  44. key := SubStr(A_ThisHotkey, 3)
  45. if (key = " ")
  46. key := "Space"
  47. ShowHotkey(prefix key)
  48. FadeOut()
  49. Return
  50. ; ===================================================================================
  51. ShowHotkey(Hotkey)
  52. {
  53. GuiControl,, HotkeyText, %Hotkey%
  54. WinGetPos, ActWin_X, ActWin_Y, ActWin_W, ActWin_H, A
  55. text_w := ActWin_W, gui_y := (ActWin_Y+ActWin_H) - 115 - 50
  56. GuiControl, Move, HotkeyText, w%text_w% center
  57. Gui, Show, NoActivate x%ActWin_X% y%gui_y% h115 w%text_w%
  58. }
  59. FadeOut(sleep = 1000)
  60. {
  61. global transN
  62. Sleep, %Sleep%
  63. Gui, +LastFound
  64. Loop, % transN
  65. WinSet, Transparent, % (A_Index - transN - 1) * -1
  66. Gui, Hide
  67. WinSet, Transparent, % transN
  68. }