显示组合键.ahk 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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
  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) - 100 -50 ;gui_y可能会
  56. GuiControl, Move, HotkeyText, w%text_w% center
  57. Try{
  58. Gui, Show, NoActivate x%ActWin_X% y%gui_y% h115 w%text_w%
  59. }
  60. }
  61. FadeOut(sleep = 1000)
  62. {
  63. global transN
  64. Sleep, %Sleep%
  65. Gui, +LastFound
  66. Loop, % transN
  67. WinSet, Transparent, % (A_Index - transN - 1) * -1
  68. Gui, Hide
  69. WinSet, Transparent, % transN
  70. }