/docs/scripts/Numpad000.ahk

http://autohotkey-chinese.googlecode.com/ · AutoHotKey · 61 lines · 32 code · 1 blank · 28 comment · 6 complexity · ca1d6506771a319c4054b05dc63079ea MD5 · raw file

  1. ; Numpad 000 Key
  2. ; http://www.autohotkey.com
  3. ; This example script makes the special 000 key that appears on certain
  4. ; keypads into an equals key. You can change the action by replacing the
  5. ; “Send, =” line with line(s) of your choice.
  6. #MaxThreadsPerHotkey 5 ; Allow multiple threads for this hotkey.
  7. $Numpad0::
  8. #MaxThreadsPerHotkey 1
  9. ; Above: Use the $ to force the hook to be used, which prevents an
  10. ; infinite loop since this subroutine itself sends Numpad0, which
  11. ; would otherwise result in a recursive call to itself.
  12. SetBatchLines, 100 ; Make it run a little faster in this case.
  13. DelayBetweenKeys = 30 ; Adjust this value if it doesn't work.
  14. if A_PriorHotkey = %A_ThisHotkey%
  15. {
  16. if A_TimeSincePriorHotkey < %DelayBetweenKeys%
  17. {
  18. if Numpad0Count =
  19. Numpad0Count = 2 ; i.e. This one plus the prior one.
  20. else if Numpad0Count = 0
  21. Numpad0Count = 2
  22. else
  23. {
  24. ; Since we're here, Numpad0Count must be 2 as set by
  25. ; prior calls, which means this is the third time the
  26. ; the key has been pressed. Thus, the hotkey sequence
  27. ; should fire:
  28. Numpad0Count = 0
  29. Send, = ; ******* This is the action for the 000 key
  30. }
  31. ; In all the above cases, we return without further action:
  32. CalledReentrantly = y
  33. return
  34. }
  35. }
  36. ; Otherwise, this Numpad0 event is either the first in the series
  37. ; or it happened too long after the first one (e.g. perhaps the
  38. ; user is holding down the Numpad0 key to auto-repeat it, which
  39. ; we want to allow). Therefore, after a short delay -- during
  40. ; which another Numpad0 hotkey event may re-entrantly call this
  41. ; subroutine -- we'll send the key on through if no reentrant
  42. ; calls occurred:
  43. Numpad0Count = 0
  44. CalledReentrantly = n
  45. ; During this sleep, this subroutine may be reentrantly called
  46. ; (i.e. a simultaneous "thread" which runs in parallel to the
  47. ; call we're in now):
  48. Sleep, %DelayBetweenKeys%
  49. if CalledReentrantly = y ; Another "thread" changed the value.
  50. {
  51. ; Since it was called reentrantly, this key event was the first in
  52. ; the sequence so should be suppressed (hidden from the system):
  53. CalledReentrantly = n
  54. return
  55. }
  56. ; Otherwise it's not part of the sequence so we send it through normally.
  57. ; In other words, the *real* Numpad0 key has been pressed, so we want it
  58. ; to have its normal effect:
  59. Send, {Numpad0}
  60. return