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 

Record and replay text key press
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
mcgyver83



Joined: 12 Nov 2007
Posts: 10

PostPosted: Mon Nov 12, 2007 12:37 pm    Post subject: Record and replay text key press Reply with quote

Hi,I want to record some key press (such as a keylogger) and replay them, starting after an hotkey press.

AutoKey can do this?

Thanks!
Back to top
View user's profile Send private message
happytodd



Joined: 12 Nov 2007
Posts: 81
Location: South Australia

PostPosted: Mon Nov 12, 2007 12:44 pm    Post subject: try this Reply with quote

Do you mean something like this script?

Code:
InputBox, MyMsg, Repeater Message
InputBox, Sleep, Repeater Timer
Gui, Add, Text, W250 +Center, Press Ctrl + Enter to start and press F1 to stop
Gui, Show
Sleep, 5000
Gui, Destroy
Return

^Enter:: ; You probably don't want just Enter as the send hotkey. Instead, use Ctrl + Enter
Loop
{
Send, {Enter} %MyMsg% {Enter}
Sleep, %Sleep%
}
Return

F1::Pause


Try it out of not reply back.
_________________

Back to top
View user's profile Send private message Visit poster's website
mcgyver83



Joined: 12 Nov 2007
Posts: 10

PostPosted: Mon Nov 12, 2007 1:40 pm    Post subject: Reply with quote

Something like it but I want to record a sequence of key typing during the first time I press them and after start replay...but at beginning I don't know the sequence...I type it always different...
Back to top
View user's profile Send private message
happytodd



Joined: 12 Nov 2007
Posts: 81
Location: South Australia

PostPosted: Mon Nov 12, 2007 1:42 pm    Post subject: help Reply with quote

thats what my program does. First box you type your message. Then next is a time in milliseconds. then Ctrl+Enter I believe to start it. Theres many programs like these on the net. If you don't know how to code one just search it on download.com
_________________

Back to top
View user's profile Send private message Visit poster's website
mcgyver83



Joined: 12 Nov 2007
Posts: 10

PostPosted: Mon Nov 12, 2007 1:54 pm    Post subject: Reply with quote

I understand this...but my"text" have to be captured during typing.I want to "read" the char sequence as fast as possible so I have to type in the second dialog box 1?
Back to top
View user's profile Send private message
happytodd



Joined: 12 Nov 2007
Posts: 81
Location: South Australia

PostPosted: Mon Nov 12, 2007 2:00 pm    Post subject: help Reply with quote

The fastest is 1, which will repeat every 1 millisecond.
_________________

Back to top
View user's profile Send private message Visit poster's website
mcgyver83



Joined: 12 Nov 2007
Posts: 10

PostPosted: Mon Nov 12, 2007 2:04 pm    Post subject: Reply with quote

But I try it on a my application... I want to simuate a user that make a road I want.
In my game the player is a man that run on a road.I want to simulate user gaming.
But when I start the script the man don't go same as I keep pressed the type.it go ,stop,go,stop,go...

And I have to record me the first time I make a track.
Some other utility that can i search?
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Mon Nov 12, 2007 5:41 pm    Post subject: Reply with quote

in general, we do not post keyloggers to the forum. They exist, and you can make one with AHK, as with many languages.

In my locality they are regulated by law. Be sure you know your local laws before playing with keyloggers.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Tue Nov 13, 2007 6:31 am    Post subject: Reply with quote

engunneer, are key-loggers illegal in your locality, or just running them without the user's consent/knowledge? Obviously if I record my own key-strokes, it does no-one any harm.

mcgyver83, since AutoHotkey has no "OnKeyPress" event, to record (any) key-press, you'll need to either:
  • create hotkeys for every key (a::, a up::, b::, etc.) either manually in script or automatically using a parsing loop (on a list of keys) and the hotkey command; or
  • research keyboard hooks (search for "WH_KEYBOARD_LL"). This way is more powerful, but more advanced (i.e. difficult.)
Either way you'll need to come up with a scheme for storing the key name or code and the time that you pressed/released it.

Alternatively, you could try AutoScriptWriter, which is included with AutoHotkey. Rolling Eyes
Back to top
View user's profile Send private message
mcgyver83



Joined: 12 Nov 2007
Posts: 10

PostPosted: Tue Nov 13, 2007 9:27 am    Post subject: Reply with quote

lexikos wrote:
engunneer, are key-loggers illegal in your locality, or just running them without the user's consent/knowledge? Obviously if I record my own key-strokes, it does no-one any harm.

I want to record my hero's track and reproduce it...so I find racer bug and store the way and understand if I solved the bug.
So i don't think that it isnj't illegal to do this on my own...

lexikos wrote:

mcgyver83, since AutoHotkey has no "OnKeyPress" event, to record (any) key-press, you'll need to either:
  • create hotkeys for every key (a::, a up::, b::, etc.) either manually in script or automatically using a parsing loop (on a list of keys) and the hotkey command; or
  • research keyboard hooks (search for "WH_KEYBOARD_LL"). This way is more powerful, but more advanced (i.e. difficult.)
Either way you'll need to come up with a scheme for storing the key name or code and the time that you pressed/released it.

Alternatively, you could try AutoScriptWriter, which is included with AutoHotkey. Rolling Eyes



I used AutoScriptWriter and it record all click and mouse movement to use my game.
It record correctly my key press to move my player but when I run my script it go all ok until it has to simulate key press... the Send, ffffff to move my man nothing move.

There is another way to simulate key press?
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Tue Nov 13, 2007 9:43 am    Post subject: Reply with quote

Quote:
There is another way to simulate key press?
"Automatic" scripts nearly always need to be adjusted; the issue isn't "simulating" the key-press, but recording it in a form that it can be accurately reproduced. (Recording key-press, key-release and timing.)

Since AutoScriptWriter is (probably) intended for automating regular Windows applications, it records only key-press (not key-release), which does no good in games. (I suppose I'd have known it wouldn't be suitable for your purpose, if I'd ever actually used it. Rolling Eyes)

Edit: Try this:
Code:
#NoEnv
keys = w,a,d,s
return

^Space::
    Status := Status="On" ? "Off" : "On"
    if Status = On
    {
        history =
        last_tick := A_TickCount
    }
regkeys:
    Loop, Parse, keys, `,
    {
        ; * to allow any modifier key
        ; ~ to not block keypress
        Hotkey, *~%A_LoopField%, keypress, %Status%
        Hotkey, *~%A_LoopField% Up, keyrelease, %Status%
    }
return

#MaxThreadsPerHotkey, 2
+Space::
    playing := !playing
    if !playing
        return
playback:
    queue := history
    Loop {
        if (i := InStr(queue,",")) {
            key := SubStr(queue, 1, i-1)
            StringTrimLeft, queue, queue, i
        } else {
            key := queue
            queue =
        }
        i := InStr(key,":")
        time := SubStr(key,1,i-1)
        key := SubStr(key,i+1)
        Sleep, %time%
        if !playing
            break
        Send {Blind}{%key%}
        if queue =
            break
    }
    playing := false
return
#MaxThreadsPerHotkey, 1

keypress:
    history .= (A_TickCount-last_tick) ":" SubStr(A_ThisHotkey,3) " down,"
    last_tick := A_TickCount
return
keyrelease:
    history .= (A_TickCount-last_tick) ":" SubStr(A_ThisHotkey,3) ","
    last_tick := A_TickCount
return
You'll probably need to change the list of keys. Smile

How it works:
  • Register the hotkeys *~w, *~w up, *~a, *~a up, etc.
  • When a hotkey is pressed, append the time since recording started and the hotkey name (excluding *~ but including " up" if applicable) to a string.
    If you pressed w, held for 200 ms, released, waited 1 second then pressed and released a, it might look like:
    Code:
    0:w down,200:w up,1000:a down,15:a up

  • For each iteration of the playback loop, "dequeue" the next item. Sleep for whatever amount of time, then send the keystroke (press or release.)
    For instance, the above sequence might look like:
    Code:
    Send {w down}
    ; next iteration
    Sleep, 200
    Send {w up}
    ; next iteration
    Sleep, 1000
    Send {a down}
    ; next iteration
    Sleep, 15
    Send {a up}

Note that comma (,) should not be used as a hotkey, since it would be seen as a delimiter. You can get around this using vkBC instead.
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Tue Nov 13, 2007 6:08 pm    Post subject: Reply with quote

lexikos wrote:
engunneer, are key-loggers illegal in your locality, or just running them without the user's consent/knowledge? Obviously if I record my own key-strokes, it does no-one any harm.


It changes per State. I believe in Washington, I can get in trouble for putting a keylogger on a customer's computer (with consent!) to monitor for a particular problem, but in other states, it is not so bad. Also, The chances of getting in trouble are small, since it would be manually mainteained on a non-networked machine, but still, It is best to caution people to at least understand the local laws. Also, we need to keep AHK's reputation good, since we don't want virus scanners going after it.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
mcgyver83



Joined: 12 Nov 2007
Posts: 10

PostPosted: Fri Nov 16, 2007 8:25 am    Post subject: Reply with quote

lexikos wrote:
Quote:
There is another way to simulate key press?
"Automatic" scripts nearly always need to be adjusted; the issue isn't "simulating" the key-press, but recording it in a form that it can be accurately reproduced. (Recording key-press, key-release and timing.)

Since AutoScriptWriter is (probably) intended for automating regular Windows applications, it records only key-press (not key-release), which does no good in games. (I suppose I'd have known it wouldn't be suitable for your purpose, if I'd ever actually used it. Rolling Eyes)

Edit: Try this:
Code:
#NoEnv
keys = w,a,d,s
return

^Space::
    Status := Status="On" ? "Off" : "On"
    if Status = On
    {
        history =
        last_tick := A_TickCount
    }
regkeys:
    Loop, Parse, keys, `,
    {
        ; * to allow any modifier key
        ; ~ to not block keypress
        Hotkey, *~%A_LoopField%, keypress, %Status%
        Hotkey, *~%A_LoopField% Up, keyrelease, %Status%
    }
return

#MaxThreadsPerHotkey, 2
+Space::
    playing := !playing
    if !playing
        return
playback:
    queue := history
    Loop {
        if (i := InStr(queue,",")) {
            key := SubStr(queue, 1, i-1)
            StringTrimLeft, queue, queue, i
        } else {
            key := queue
            queue =
        }
        i := InStr(key,":")
        time := SubStr(key,1,i-1)
        key := SubStr(key,i+1)
        Sleep, %time%
        if !playing
            break
        Send {Blind}{%key%}
        if queue =
            break
    }
    playing := false
return
#MaxThreadsPerHotkey, 1

keypress:
    history .= (A_TickCount-last_tick) ":" SubStr(A_ThisHotkey,3) " down,"
    last_tick := A_TickCount
return
keyrelease:
    history .= (A_TickCount-last_tick) ":" SubStr(A_ThisHotkey,3) ","
    last_tick := A_TickCount
return
You'll probably need to change the list of keys. Smile

How it works:
  • Register the hotkeys *~w, *~w up, *~a, *~a up, etc.
  • When a hotkey is pressed, append the time since recording started and the hotkey name (excluding *~ but including " up" if applicable) to a string.
    If you pressed w, held for 200 ms, released, waited 1 second then pressed and released a, it might look like:
    Code:
    0:w down,200:w up,1000:a down,15:a up

  • For each iteration of the playback loop, "dequeue" the next item. Sleep for whatever amount of time, then send the keystroke (press or release.)
    For instance, the above sequence might look like:
    Code:
    Send {w down}
    ; next iteration
    Sleep, 200
    Send {w up}
    ; next iteration
    Sleep, 1000
    Send {a down}
    ; next iteration
    Sleep, 15
    Send {a up}

Note that comma (,) should not be used as a hotkey, since it would be seen as a delimiter. You can get around this using vkBC instead.



Ok, I can assign w,s,a,d as movement key and a don't have to add anymore key.
I'm beginner with autoHotKey and I don't understand when the script start to record my key typing and where can I find the "history" of key typed and how can I start playback....

Sorry but I'm very beginner...
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2558
Location: Australia, Qld

PostPosted: Fri Nov 16, 2007 8:54 am    Post subject: Reply with quote

There are two hotkeys: ^Space and +Space. (You can, of course, change these.) ^Space starts or stops "recording," and +Space starts or stops "playback." Since "recording" is simply building a string of hotkeys that are pressed and the times they are pressed at (relative to when you pressed ^Space), you can find the "history" in none other than the variable "history." Rolling Eyes

In case you haven't read the manual, ^ is ctrl and + is shift.
Back to top
View user's profile Send private message
mcgyver83



Joined: 12 Nov 2007
Posts: 10

PostPosted: Fri Nov 16, 2007 4:46 pm    Post subject: Reply with quote

Thaks a lot...this evening I try your script...
Ok for shift and control,i find it on tutorial.
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
Goto page 1, 2  Next
Page 1 of 2

 
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