AutoHotkey Community

It is currently May 26th, 2012, 3:21 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: April 11th, 2008, 7:01 pm 
Offline

Joined: February 25th, 2008, 4:13 pm
Posts: 37
I'm new to AHK, so if there are ways to improve the code, please let me know.

The idea is to be able to easily record a set of keystrokes, and play them back multiple times. It's great for getting rid of commas at the end of lines, adding them, etc.

Code:
bRecording = 0
sMacro := ""
ShiftState := "U"
ControlState := "U"
AltState := "U"
Loop
{
   Input, UserInput, L1 V, {F6}

    if bRecording = 1
    {
       ;MsgBox "Adding to sMacro " %UserInput%
        HandleKeyStates()
       sMacro = %sMacro%%UserInput%
    }
}

    F6::  ;MsgBox "Pressed F6"
        if %bRecording% = 0
        {
            bRecording = 1
            sMacro := ""
        }
        else
        {
            bRecording = 0
            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%
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 11th, 2008, 7:58 pm 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
I played around with it a bit and like it - I've often wanted something like this for when I'm doing something repetetive that isn't enough of a pain to justify a new script...

Feature requests:
A tooltip that indicates when you're in 'recording' mode.
Option to perform the recorded action X times.
The option to record time delay between keys.

Thanks for sharing!

_________________
[Join IRC!]
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 11th, 2008, 8:44 pm 
Offline

Joined: February 25th, 2008, 4:13 pm
Posts: 37
Added icons to indicate recording status. Download available here.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 17th, 2008, 3:32 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
People interested in the above script may also want to look at:

DoOver - Record and playback keyboard and mouse actions.
http://www.donationcoder.com/Software/S ... DoOver.ahk

Features:
- User defined hotkeys.
- Recorded macro can be edited through the Settings menu before
playback.
- Change playback speed through the Settings menu.
- Press Ctrl-F12 to start and stop recording.
- Press Ctrl-F5 to start playback.
- Press Esc to abort playback.
- Won't move windows due to relative mouse actions.

Automate repetitive tasks in Windows (especially Excel)
http://www.autohotkey.com/forum/topic19051.html

This script looks for a repetitive pattern in your keystrokes and
mouse clicks. When it is sure that it has discovered a repetitive
pattern, it asks you whether you would like to repeat the pattern


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group