 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
airjrdn
Joined: 25 Feb 2008 Posts: 35
|
Posted: Tue Apr 08, 2008 7:14 pm Post subject: Hotkey (begin recording) Hotkey (end ...) Hotkey (play ...) |
|
|
I put something together in VB, but I already have another AutoHotkey executable that runs in the background all the time, and it would be nice to not have 3 or 4 of these when they could all probably be combined into a single, more useful tool.
What I have now allows you to set your Record & Playback Keys. The Record Key toggles recording, the Playback key simply plays it back. It's great for adding commas to the end of code (SQL), or removing things, etc.
The VB app is doing sys hooks to capture all keystrokes, and works fairly well, but strangely, negates Alt-Tab from working when Firefox is the topmost window. I haven't figured out why just yet.
I've looked at Is this possible to do with AHK (keyboard hook) as well as WinEventHook example... and Record and replay text key press but none seem to offer a finished solution on how to do this.
Any assistance would be appreciated.
Edit - here's the latest code. I think it's working!
| Code: |
;#InstallKeybdHook
;#UseHook
bRecording = 0
sMacro := ""
ShiftState := "U"
ControlState := "U"
AltState := "U"
Loop
{
Input, UserInput, L1 V, {F6} ;MsgBox "Key Pressed - " %UserInput%
if bRecording = 1
{
;MsgBox "Adding to sMacro " %UserInput%
HandleKeyStates()
sMacro = %sMacro%%UserInput%
}
}
F6:: ;MsgBox "Pressed F6"
if %bRecording% = 0 ;set recording mode
{
bRecording = 1 ;MsgBox "Begin Recording"
sMacro := ""
}
else
{
bRecording = 0 ;MsgBox "End Recording"
ShiftState := "U"
ControlState := "U"
AltState := "U"
}
Return
F7::
SendInput %sMacro%
Return
~+F7::
MsgBox %sMacro%
Return
~+Up::
~+Down::
~+Left::
~+Right::
~+Home::
~+End::
~+Backspace::
~+Delete::
~+PgUp::
~+PgDn::
~+Insert::
~+Tab::
~Up::
~Down::
~Left::
~Right::
~Home::
~End::
~Backspace::
~Delete::
~PgUp::
~PgDn::
~Tab::
~Insert::
^Up::
~^Down::
~^Left::
~^Right::
~^Home::
~^End::
~^Backspace::
~^Delete::
~^PgUp::
~^PgDn::
~^Tab::
~^Insert::
~F2::
~F3::
~F4::
if bRecording = 1
{
keyPressed = %A_ThisHotKey%
HandleKeyStates()
StringReplace, keyPressed, keyPressed, +, , All
StringReplace, keyPressed, keyPressed, ~, , All
StringReplace, keyPressed, keyPressed, ^, , All
sMacro = %sMacro%{%keyPressed%}
}
Return
HandleKeyStates()
{
global
GetKeyState, sstate, Shift
if ShiftState != %sstate%
if sstate = D
sMacro = %sMacro%{shift down}
else
sMacro = %sMacro%{shift up}
ShiftState = %sstate%
GetKeyState, cstate, Control
if ControlState != %cstate%
if cstate = D
sMacro = %sMacro%{ctrl down}
else
sMacro = %sMacro%{ctrl up}
ControlState = %cstate%
GetKeyState, astate, Alt
if AltState != %astate%
if astate = D
sMacro = %sMacro%{alt down}
else
sMacro = %sMacro%{alt up}
AltState = %astate%
}
|
Last edited by airjrdn on Thu Apr 10, 2008 8:02 pm; edited 6 times in total |
|
| Back to top |
|
 |
airjrdn
Joined: 25 Feb 2008 Posts: 35
|
Posted: Tue Apr 08, 2008 10:37 pm Post subject: |
|
|
Ok, this captures letters, numbers, etc. It uses F6 to start/stop recording, and F7 to playback.
The problem is, playback (and I suppose recording) doesn't take into account everything, such as the spacebar, or arrow keys, etc. I'm looking for those to be captured, as well as home/end/shift/ctrl/pgup/pgdn.
Here's what I have so far.
| Code: |
bRecording = 0
sMacro := ""
sp := "R"
Loop
{
Input, UserInput, L1 V, {F6}
StringLen, sLen, UserInput
if sLen > 0
{
;MsgBox "UserInput - " %UserInput%
;MsgBox "bRecording - " %bRecording%
if bRecording = 1
{
;MsgBox "Adding to sMacro " %UserInput%
sMacro = %sMacro%%UserInput%
}
}
}
F6:: ;MsgBox "Pressed F6"
if %bRecording% = 0 ;set recording mode
{
;MsgBox "Begin Recording"
bRecording = 1
sMacro := ""
}
else
{
;MsgBox "End Recording"
bRecording = 0
}
Return
F7::
;MsgBox %sMacro%
Send %sMacro%
Return
|
|
|
| Back to top |
|
 |
pantagruel
Joined: 08 Oct 2006 Posts: 67 Location: denmark
|
|
| Back to top |
|
 |
airjrdn
Joined: 25 Feb 2008 Posts: 35
|
Posted: Thu May 15, 2008 3:39 pm Post subject: |
|
|
No, I don't think I'd seen that, thanks for the link.
I ended up getting my version working, as well as adding some other functionality as well. The thread for my new all-in-one ahk app is here |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|