AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hotkey (begin recording) Hotkey (end ...) Hotkey (play ...)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
airjrdn



Joined: 25 Feb 2008
Posts: 35

PostPosted: Tue Apr 08, 2008 7:14 pm    Post subject: Hotkey (begin recording) Hotkey (end ...) Hotkey (play ...) Reply with quote

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
View user's profile Send private message
airjrdn



Joined: 25 Feb 2008
Posts: 35

PostPosted: Tue Apr 08, 2008 10:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
pantagruel



Joined: 08 Oct 2006
Posts: 67
Location: denmark

PostPosted: Thu May 15, 2008 2:00 pm    Post subject: instantdoover Reply with quote

Hi,

have you looked at InstantDoOver http://www.autohotkey.com/forum/topic31257.html

does it help?
Back to top
View user's profile Send private message
airjrdn



Joined: 25 Feb 2008
Posts: 35

PostPosted: Thu May 15, 2008 3:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group