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 

InstantDoOver

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
interiot



Joined: 06 Nov 2005
Posts: 64

PostPosted: Sun Apr 27, 2008 8:33 pm    Post subject: InstantDoOver Reply with quote

This is a variant of Skrommel's DoOver script that lets you record a sequence of keys, and then play them back as fast as possible.

Code:
; A quick keystroke-record/keystroke-playback script.
;   Press Ctrl-F12 to start and stop recording.
;   Press Ctrl-F5 to playback.
;
;   Press Ctrl-F11 to toggle between Send/SendPlay/SendInput
;   Press Ctrl+plus/Control+minus to change the hold-down key duration
;   Press Ctrl-asterisk/Control-slash to change the inter-key gap duration
;
; NOTE: there are two ways to do macro recording like this...
;   1) record every key-down, key-up, and the time delay in between,
;      and faithfully play the keys back with the same timing.
;      However, this can be slow.
;   2) record just the individual key-repeats, and play the keys back as fast as possible.
;      However, this doesn't work for programs that want the key-down/key-up data.
;
; This script takes the second approach.  If you need the first approach, see
;   http://www.donationcoder.com/Software/Skrommel/#DoOver

#SingleInstance force

currentlyRecording := 0
send_mode = Event
holddown := -1
between := -1

; register all 255 virtual keys
SetFormat,Integer,Hex
Loop, 255
{
   key := substr("0" . substr(A_Index + 0, 3), -2)      ; convert to hex, remove "0x", pad to two digits
   Hotkey, *~vk%key%, AnyKey_down
   Hotkey, *~vk%key% up, AnyKey_up
}
SetFormat,Integer,Decimal


AnyKey_down:
   if (currentlyRecording)
      playback := playback . "{" . substr(A_ThisHotkey,3). " Down}"
   return

AnyKey_up:
   if (currentlyRecording)
      playback := playback . "{" . substr(A_ThisHotkey,3). "}"
   return


^F5::
   if (currentlyRecording)      ; stop recording if we haven't already
      gosub ^F12
   if (GetKeyState("F5", "P")) {   ; don't keep repeating after we've let go
      SendMode, %send_mode%
      SetKeyDelay, between, holddown
      Send,%playback%
   }
   return


^F12::
   if (currentlyRecording) {
      ToolTip,Stopped recording.
      currentlyRecording := 0
      playback := RegExReplace(playback, "(\{[^}]+ Down\})+$", "")   ; remove the "^F5" from the end
   } else {
      ToolTip,Started recording.
      currentlyRecording := 1
      playback := ""
   }
   SetTimer,ToolTipOff,1000
   return

^F11::
   if (send_mode == "Event") {
      send_mode := "Input"
   } else if (send_mode == "Input") {
      send_mode := "Play"
   } else if (send_mode == "Play") {
      send_mode := "Event"
   }
   ToolTip,Send%send_mode%
   SetTimer,ToolTipOff,1000
   return


^NumpadAdd::
   holddown := holddown + (holddown >= 25 ? 10 : 1)
   ToolTip,Hold-down = %holddown%ms
   SetTimer,ToolTipOff,1000
   return

^NumpadSub::
   holddown := holddown - (holddown > 25 ? 10 : 1)
   if (holddown < -1)
      holddown := -1
   ToolTip,Hold-down = %holddown%ms
   SetTimer,ToolTipOff,1000
   return

^NumpadMult::
   between := between + (between >= 25 ? 10 : 1)
   ToolTip,Between gap = %between%ms
   SetTimer,ToolTipOff,1000
   return

^NumpadDiv::
   between := between - (between > 25 ? 10 : 1)
   if (between < -1)
      between := -1
   ToolTip,Between gap = %between%ms
   SetTimer,ToolTipOff,1000
   return
   

ToolTipOff:
   SetTimer,ToolTipOff,Off
   ToolTip
   return

(actually, this code is a rewrite... there are various ways of watching all keystrokes, and I hadn't seen any example code yet that creates a hotkey for each of the 255 virtual keys, so this does that)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions 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