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