ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA: "WaitAndSend" - timer/keyboard macro combo program...

(1/2) > >>

Onesimus Prime:
I may not know the depth of what I'm asking for, but here goes...

Would it be possible to have a program that, at a customizable system time or in 'x' mintes/seconds, makes sure that program 'y' is focused and sends it user-definable keystrokes?  And it'd be nice if this were "portable," not writing outside its own directory.

The situation prompting this request...
I'm recording a professor's lectures, and sometimes have to ditch class and leave the computer recording when he goes over-time.  After my next class, I come back and stop the recording--but this means that there's well over an hour of silence at the end of the recorded file!  And, even compressed, that takes up HD space, sometimes more than I have.  
So I was thinking it would be nice to have a program do something like, in my case, "in 10 minutes, switch to Reaper (going off of window titles?) and send key combination Ctrl+R (or whatever it is) to stop recording." (I guess by default, space is stop, but the possibility for key combinations--even a few combos in succession, maybe with "sleep" pauses in between, would maximize flexibility for other possible uses)

If anyone can help with this without too much trouble (or knows of something similar and portable), it'd be much appreciated!  Thanks!

*edit* - it's got a name now!

skwire:
This is the perfect scenario for a simple personal AutoHotkey script.  http://www.autohotkey.com  The commands you're going to want to look up are Sleep, Send, WinActivate, and WinWaitActive.  If you're not able to write it yourself, let us know and we'll help out.

Onesimus Prime:
I forgot about "WinActivate and WinWaitActive" - I'll look into those.  I think I've used the other commands before. Thanks!

Oh, I forgot--will this still work if the computer's "locked"?

skwire:
I forgot about "WinActivate and WinWaitActive" - I'll look into those.  I think I've used the other commands before. Thanks!

Oh, I forgot--will this still work if the computer's "locked"?
-Onesimus Prime (February 18, 2010, 01:33 AM)
--- End quote ---

Doubtful.

Onesimus Prime:
I so should have been sleeping... *chagrined*
Okay, I first wrote a simple one like what you described, skwire--about 4 lines is all it takes, I didn't realize it'd be so simple!  But then I couldn't leave well enough alone...  I did a forum search, grabbing the countdown timer code from https://www.donationcoder.com/forum/index.php?topic=14895.0 and integrating the use of an .ini file (thanks to Skrommel's stuff), and the below is the (seemingly working) monstrosity that resulted  ;D :

--- ---applicationname=WaitAndSend
versionnumber=0.5

; by Onesimus Prime
; 2009
; For now, right-click on the tray icon to exit...

; Countdown timer code (which is the majority of what's below) from

https://www.donationcoder.com/forum/index.php?topic=14895.0
; Some .ini-related code from Skrommel's templates

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey

releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and

reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#persistent

IfNotExist,%applicationname%.ini
{
  ini=[Settings]
  ini=%ini%`n
  ini=%ini%`nctimer=20
  ini=%ini%`n  `; This sets the countdown, unless it is over-ridden by

launching the script with a numeric parameter.
  ini=%ini%`n  `; It is measured in minutes (and decimals are valid).
  ini=%ini%`n
  ini=%ini%`ntargetprogram=ahk_class REAPERwnd
  ini=%ini%`n  `; this is the Title or Class of the window of the target

program, the program that you wish to send the below keystrokes to. 
  ini=%ini%`n  `; By default, this line includes "ahk_class REAPERwnd",

summoning a window with the class matching the REAPER recording program.
  ini=%ini%`n
  ini=%ini%`nkeypresses={Space}
  ini=%ini%`n  `;the keystrokes here will be sent to the program listed above.

 Your options, and the various formatting restrictions, are viewable at

http://www.autohotkey.com/docs/commands/Send.htm
  ini=%ini%`n  `; By default, this line simulates a press of the Spacebar

(using {Space}),  which (by Reaper's defaults) toggles "play" and "stop" (and

thus can be used to stop recording!)
  ini=%ini%`n  `; You could also use {CTRLDOWN}r{CTRLUP} to send Ctrl+R,

Reaper's default key combo to START recording.
  FileAppend,%ini%,%applicationname%.ini
  ini=
}

IniRead, ctimer, %applicationname%.ini, Settings, ctimer

IniRead, targetprogram, %applicationname%.ini, Settings, targetprogram
IniRead, keypresses, %applicationname%.ini, Settings, keypresses

CoordMode, ToolTip, Screen
tt = %1%
if not tt
   tt = %ctimer%
;tt = 120
time := Convert_Milliseconds(tt)
Sec := (tt * 60)

SetTimer, nMessage, %time%
countdown(Sec)
return

nMessage:
SetTimer, nMessage, Off

WinActivate %targetprogram%
WinWaitActive %targetprogram%
send %keypresses%
sleep 1000
; MsgBox Your keypresses have been sent to the requested program.
Gui, +MinimizeBox
GUi, -sysmenu
gui, +toolwindow
Gui, Add, Button, w130, DONE - hit 'O' for OK
Gui, Show, x1 y1, %applicationname% %versionnumber%

KeyWait, o, D
Tooltip ,, 2, 980
Gui Destroy
exitapp


Convert_MilliSeconds(time,MS = 1000,M = 60)
{
   return MS*M*time
}

countdown(p_count="") {
   countdown_time:=p_count
   countdown_date=16010101
   countdown_date+=%countdown_time%, s
   Loop {
      If (countdown_date >= 16010101010000){
        FormatTime, mmss, %countdown_date%, hh:mm:ss
     }else{
      FormatTime, mmss, %countdown_date%, mm:ss
      }
      ;msgbox %countdown_date%`n%hhmmss%
     ;//SB_SetText(mmss, 2)
      Tooltip, %mmss%, 2000,14
      Menu,Tray,Tip,Time Remaining: %mmss%
      Sleep, 1000
      countdown_date+=-1, s
      ;//IfLess, countdown_date, 16010101, break
      if (A_Index>countdown_time) {
         break
      }
   }
}

You were right about a "locked" computer--it seems to wait until the computer is unlocked before executing the after-timer stuff.  One workaround, I guess, might be to use KidSafe Portable to "lock" the computer instead.  "Windows + L can cut off some processes (e.g. it always pauses my virus scanner and media player, and turns off my Internet); KidSafe doesn’t do that" (according to a quote here).

Navigation

[0] Message Index

[#] Next page

Go to full version