显示组合键.ahk 2.0 KB

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