4

I'm using an AutoHotKey script in Windows 7 to send the contents of the clipboard as a series of keystrokes. I'm very new to AutoHotKey, but I was wondering if there was some way to adjust the time between each keystrokes that it sends. Currently, the only line in my script is as follows:

^!k:: Send %clipboard%

I'd like to be able to increase the time between keystrokes (currently it seems to be on the order of about 50 characters per second) to more like 10 characters per second.

I'm using this to send keystrokes to a microcontroller using a terminal emulator. I'm having issues in that when I actually type in the keystrokes manually, everything registers as it should, but when I send the clipboard contents as keystrokes, something goes wrong, and I was hoping to slow down the rate of input in an attempt to pinpoint the issue. Essentially, I'd like to rule out the speed of input as an issue before attempting another more complicated solution.

If anybody has any ideas it'd be much appreciated. Thanks!

Benoit Duffez
  • 11,839
  • 12
  • 77
  • 125
wickstopher
  • 981
  • 6
  • 18

3 Answers3

5

You can use this function

USING

Sendpersec(Clipboard, 10)

OR

Sendpersec("jdkfjdkjdfkjdfkjdfkdfjdf", 5)

FUNCTION

Sendpersec(Data, Chs){
sleeptime := 1000 / Chs
IfLess,sleeptime,1
    sleeptime := 1
loop,
{
StringLeft,tosend,Data,1
Send, %tosend%
sleep,%sleeptime%
StringTrimLeft,Data,Data,1
IfEqual,Data
    break
}
}
Avi
  • 1,341
  • 1
  • 18
  • 28
  • The second param is the no of charactets per second . Tell me if this doesnt work – Avi May 06 '13 at 11:42
  • This, my friend, was the perfect solution. I'm happy to report that not only did this work perfectly, it solved the overarching problem as well (my microcontroller just couldn't handle the rate of input and was choking up). It's worth noting here that I had to store the contents of the clipboard using a variable (Clipboard = %clipboard%) and then call the function using that variable. Thanks so much. If I had a reputation on this site, I'd upvote the crap out of your solution. – wickstopher May 06 '13 at 18:06
  • @cecilg23 This is my first accepted answer here. Thanks to you too . – Avi May 07 '13 at 08:51
2

An easy way to increase the typing speed is to use SendInput instead of Send. This will "type" much faster ! Alternatively, you can store the string in ClipBoard and use Send, ^v to send it.

Example:

Clipboard= Long string to type
Send, ^v
Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32
1

Yes, use Sleep, DelayInMilliseconds. For example for 10 key strokes per second, you'd use a delay of 100

http://www.autohotkey.com/docs/commands/Sleep.htm

EDIT: Maybe you want this then: SetKeyDelay [, Delay, PressDuration, Play] "Sets the delay that will occur after each keystroke sent by Send and ControlSend."

http://www.autohotkey.com/docs/commands/SetKeyDelay.htm

Patashu
  • 21,443
  • 3
  • 45
  • 53
  • I'm not sure if that was quite what I was looking for. I can see how that would be useful when you're giving it a specific chain of commands and you want a specific delay between execution, but the situation I'm describing is where there are an unknown quantity of characters on the clipboard, and I want to send them all as keystrokes, with 100 milliseconds (or whatever) in between each keystroke. – wickstopher May 06 '13 at 02:47
  • @cecilg23 Hmm, you're right, is this what you want then? (Edited answer) – Patashu May 06 '13 at 03:16
  • 1
    Could you possibly provide an example? It seems like this is what I want but I'm not having any success. Current code is as follows: SetKeyDelay, 1000 ^k:: Send %clipboard% this has no effect on the original behavior. – wickstopher May 06 '13 at 03:39
  • @cecilg23 Hmmm, if that's not it either I have no clue. Sorry :) – Patashu May 06 '13 at 03:41