PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/res/ahk/recorder.ahk

http://github.com/Skiouros/Macro
AutoHotKey | 75 lines | 63 code | 9 blank | 3 comment | 3 complexity | d44bdc44fd8109624d2faf22798d6703 MD5 | raw file
  1. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. #Persistent
  3. #SingleInstance, Force
  4. #NoTrayIcon
  5. SetBatchLines, -1
  6. ListLines, Off
  7. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  8. EndKeys := "
  9. ( LTrim
  10. LWin RWin AppsKey
  11. LShift RShift LControl RControl LAlt RAlt
  12. F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
  13. Left Right Up Down
  14. Insert Delete Home End PgUp PgDn
  15. Space Tab Enter Escape Backspace
  16. CapsLock NumLock ScrollLock
  17. PrintScreen Pause
  18. Numpad0 Numpad1 Numpad2 Numpad3 Numpad4
  19. Numpad5 Numpad6 Numpad7 Numpad8 Numpad9
  20. NumpadIns NumpadEnd NumpadDown NumpadPgDn NumpadLeft
  21. NumpadClear NumpadRight NumpadHome NumpadUp NumpadPgUp
  22. NumpadDot NumpadDel
  23. NumpadDiv NumpadMult NumpadSub NumpadAdd NumpadEnter
  24. )"
  25. StringReplace, endKeys, endKeys, `n, %A_Space%, All
  26. keys := "qwertyuiopasdfghjklzxcvbnm1234567890-=[]\;',./"
  27. mouseButtons := "RButton,LButton,MButton"
  28. Loop, Parse, keys
  29. Hotkey, % A_LoopField, Keys
  30. Loop, Parse, EndKeys, %A_Space%
  31. Hotkey, % A_LoopField, Keys
  32. if (mouseClicks)
  33. Loop, Parse, mouseButtons, `,
  34. Hotkey, % "~" . A_LoopField, Keys
  35. return
  36. Keys:
  37. StringReplace, Hotkey, A_ThisHotkey, ~
  38. done := 0
  39. if hotkey in %mouseButtons%
  40. {
  41. if (location)
  42. {
  43. MouseGetPos, x, y
  44. Send("MouseMove, " . x . ", " . y . "`n")
  45. }
  46. }
  47. msg := "{" . Hotkey . " Down}`n", Send(msg)
  48. KeyWait % Hotkey
  49. msg := ( (delay ? ("Sleep, " . (done ? A_TimeSincePriorHotkey - A_TimeSinceThisHotkey -30 : A_TimeSinceThisHotkey - 30) . "`n") : "")
  50. . "{" . (done ? A_PriorHotkey : Hotkey) . " Up}`n" )
  51. Send(msg)
  52. done := 1
  53. return
  54. Send(ByRef StringToSend) ; ByRef saves a little memory in this case.
  55. ; This function sends the specified string to the specified window and returns the reply.
  56. ; The reply is 1 if the target window processed the message, or 0 if it ignored it.
  57. {
  58. global PID
  59. VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0) ; Set up the structure's memory area.
  60. ; First set the structure's cbData member to the size of the string, including its zero terminator:
  61. SizeInBytes := (StrLen(StringToSend) + 1) * (A_IsUnicode ? 2 : 1)
  62. NumPut(SizeInBytes, CopyDataStruct, A_PtrSize) ; OS requires that this be done.
  63. NumPut(&StringToSend, CopyDataStruct, 2*A_PtrSize) ; Set lpData to point to the string itself.
  64. SendMessage, 0x4a, 0, &CopyDataStruct,, ahk_pid %PID% ; 0x4a is WM_COPYDATA. Must use Send not Post.
  65. return ErrorLevel ; Return SendMessage's reply back to our caller.
  66. }