 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Mike0627
Joined: 13 Mar 2010 Posts: 4
|
Posted: Tue Mar 16, 2010 1:44 pm Post subject: help with program for disabled son |
|
|
Hi,
I am writing an AHK program that will basically use Windows Media Player to play a DVD for an certain number of seconds (variable) then pause the player, wait for and "ENTER" input from the user and then resume the DVD... again for the requested number of seconds. I have made some progress (new to any programming) but now I need some advice please.
Here's what I have accomplished
- AHK will start and ask for the number of seconds the therapist wishes it to run (%secs%)
- If Windows Media Player is not active it will start it
- It will wait for the DVD to be manually started and for the therapist to click "OK"
************************
HERE'S WHERE I AM STUCK - THIS IS WHAT I NEED FROM HERE ...
I would like AHK to enter a loop (?) and count up to the number of %secs% - then send a pause command to Windows Media Player (CONTROL+P) - then wait for an "ENTER" input and then send a run command to WMP (CONTROL+P) - then start counting the seconds again up to the number of %secs% specified - send a pause ---- etc etc etc
To end the program at anytime I need to add a line that would make ESCAPE (?) quit AHK & WMP
I am very appreciative for any help I can get.
Thank you,
Mike |
|
| Back to top |
|
 |
ScottMattes
Joined: 21 May 2007 Posts: 173 Location: USA
|
Posted: Tue Mar 16, 2010 1:59 pm Post subject: |
|
|
No need for the loop, use
Sleep
--------------------------------------------------------------------------------
Waits the specified amount of time before continuing.
Sleep, DelayInMilliseconds
once the Therapist clicks OK start a timer that points to the pause code. setup a trigger on ENTER to send the run command and another trigger to quit.
It sounds like you are learning a lot, keep asking questions - we ALL love to help. _________________ -------------
Scott Mattes
My small, and slowly growing, collection of scripts. |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
Posted: Tue Mar 16, 2010 8:03 pm Post subject: |
|
|
Hello Mike0627,
My M.O. is usually to help to bring other members along by giving pointers as to where to find the solution,
so that they learn "where to find the solution".
>>help with program for disabled son
To me that ranks well above helping someone with another WOW script.
May I offer this script as well-wishes to you, he, and any others near to you.
I hope this spurs you on to more Ahk.
I have not tested the WMPlayer aspect, because I don't allow the program on my computer
(it used to query an inserted flash drive every 10-15 seconds )
| Code: | min_play=3
play_time=6 ;<---- time to play DVD in seconds
max_play=10
screen_x=0 ; customize location of window, if desired
screen_y=0 ; see "gui, show" below to enable
OnExit, quit ;
title=DVD Play Timer
gui, font,s12
gui, add, text, , %title%
gui, font,s10
gui, add, text, center xm , Play Time (secs)
gui, add, edit, w70
Gui, Add, UpDown, vplay_time Range%min_play%-%max_play%, %play_time%
gui, add, button, yp x+10 vok Default, OK
;gui, add, button, x30 vok Default, OK
gui, add, text, center xm , Press Ok or Enter `nafter movie started
gui, add, text, center xm, Press ESC`nto exit at any time
show_gui:
;==================================================================
; gui position, default of centered on screen
gui, show, w150 h180 ,DVD play timer
;==================================================================
; gui position, --customized--
;gui, show, w150 h180 x%screen_x% y%screen_y%,DVD play timer
return
buttonOK: ; the assumption is that the DVD has been started manually prior the button push
gui, submit ; gets the current sleep time and hides the gui
sleep, play_time * 1000 ; sleep command is based on units of 1/1000 second
send ^p ; normal way to send control-p
; some systems may be stubborn and require alternate control-p
; for now this next line is commented out and will not be run
; send {control down} p {control down}
goto show_gui ; show the interface again
GuiClose:
esc::
exitapp
quit:
; winclose, Untitled ; close a window with title that starts "Untitled"
; winclose, ahk_class Notepad ; close a window of class matching notepad
winclose, ahk_class WMPlayerApp ; this may be right for WMP, I dunno.
exitapp
;f12::reload ; used for development purposes
;f1:: ; to find the window class, run the script, place mouse over window and hit F1
MouseGetPos,,, WinID
WinGetClass, class, ahk_id %WinID%
clipboard=ahk_class %class%
msgbox window class copied to clipboard`nahk_class %class%
return |
|
|
| Back to top |
|
 |
Mike0627
Joined: 13 Mar 2010 Posts: 4
|
Posted: Wed Mar 17, 2010 1:46 am Post subject: |
|
|
Thank you both so much. I can't believe how fqast those answers came. THanks also for all the coding work, I am truly thankful for all your effort. I do not understand the GUI stuff, so that is going to be a learning curve if that is the way I need to go.
Here is what I have done so far. Bear with me - this is a few days work for me! You will see my notes in CAPS about 3/4 of the way down. MAybe I am way off base in how I am trying to accomplish this. I am grateful for any help.
I am sorry I saw this reply so late, I will check out the GUI code in the morning. Thanks to all!!
| Code: |
#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.
#SingleInstance force
; HotKey, Esc, on ; Assign a hotkey to terminate this script.
MsgBox, 4,Bretts DVD timer , This will start and run Bretts DVD timer program`n `nWould you like to continue?, 605 ; 60-second timeout.
IfMsgBox, No
ExitApp ; User pressed the "No" button.
InputBox, secs, Set Timer, Enter the number of seconds for the program to run between prompts?, , , 250 , 50 , , , 60 , 60
time=%secs%*1000
IfMsgBox Timeout, ExitApp
; check to see if player active
IfWinActive, Windows Media Player
WinMaximize ; Maximizes the window found by IfWinActive above.
Else run "C:\Program Files\Windows Media Player\wmplayer.exe" /open
Sleep 1000
IfWinActive, Windows Media Player
MsgBox, 4145, Do This Now!!, While this window is up insert the DVD into the player and start it playing.`n `nThe DVD will play for %secs% seconds then pause for input.`n Once the DVD is playing select OK to start the timer. `nHitting "Cancel" will EXIT the program., 120
IfMsgBox, Cancel
WinClose, Windows Media Player
*************************************8****************
******************************************************
; HERE IS WHERE MY NEXT CHALLENGE IS - THIS WILL WAIT THE RIGHT NUMBER OF SECONDS,
; AND SEND A SERIES OF COMMANDS THAT WIL PAUSE MEDIA PLAYER - THAT WORKS...
; KEYWAIT DOES NOT WORK... IT JUST SKIPS RIGHT BY IT
; I WANT THE PROGRAM TO PAUSE WHERE THE KEYWAIT IS ... AND WAIT FOR {ENTER}
; THEN RUN THE LOOP AGAIN....
;
; i ALSO NEED TO ASSIGN A HOTKEY SO {escape} WILL QUIT THE APP WHENEVER IT IS PRESSED.
; I TRIED A LINE FOR THAT UP TOP BUT IT DIDN'T WORK....
loop
{
Sleep, (secs*1000)
ControlFocus, Windows Media Player
Send {Alt}
Send P
Send {ENTER}
SoundBeep, ,1500]
KeyWait, {Enter}
}
|
Mike |
|
| Back to top |
|
 |
Tyrsius
Joined: 09 Jul 2009 Posts: 140
|
Posted: Wed Mar 17, 2010 2:15 am Post subject: |
|
|
Mike, there are a number of ways to accomplish what you are trying to do. It the GUI method above looks like too much for you, using an inputbox to gather the time is just fine.
I would recommend using a timer instead of a loop. Also, your Keywait function should not use the curly brackets to name the key, this is likely the issue. I will leave learning timers to you though, I don't want to give you any code you can't figure out yourself.
When you make a hotkey using the Hotkey command, the second parameter is not on/off, it is the label to use. The esc key does not have a function until you give it one, simply turning it on as a hotkey will not make it exit the program. If you are just trying to make the escape key exit the program, the Hotkey command is probably the wrong way to go about it. You can define hotkeys using a double-colon label directly like this:
| Code: |
;single line method
ESC::exitapp
;multiple line method (use when the key will execute more than one line of code)
ESC::
msgbox, You pressed the ESC key, the program will not exit.
WinKill, Windows Media Player
exitapp
|
Here is your script, with some small modifications. I still recommend reviewing the linked documentation. (Like leef-me, I cannot test this due to not having Windows Media Player)
| Code: |
#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.
#SingleInstance force
MsgBox, 4,Bretts DVD timer , This will start and run Bretts DVD timer program`n `nWould you like to continue?, 605 ; 60-second timeout.
IfMsgBox, No
ExitApp ; User pressed the "No" button.
InputBox, secs, Set Timer, Enter the number of seconds for the program to run between prompts?, , , 250 , 50 , , , 60 , 60
time=%secs%*1000
IfMsgBox Timeout, ExitApp
; check to see if player active
IfWinActive, Windows Media Player
WinMaximize ; Maximizes the window found by IfWinActive above.
Else run "C:\Program Files\Windows Media Player\wmplayer.exe" /open
Sleep 1000
IfWinActive, Windows Media Player
MsgBox, 4145, Do This Now!!, While this window is up insert the DVD into the player and start it playing.`n `nThe DVD will play for %secs% seconds then pause for input.`n Once the DVD is playing select OK to start the timer. `nHitting "Cancel" will EXIT the program., 120
IfMsgBox, Cancel
WinClose, Windows Media Player
loop,
{
sleep, %time%
ControlFocus, Windows Media Player
Send !p
Send {ENTER} ;I left this in, because I am not sure why you had it there to begin with
SoundBeep, ,1500
sleep, 100
KeyWait, Enter
}
ESC:: ;This key should exit both the script and Windows media player when pressed
msgbox, You pressed the ESC key, the program will not exit.
WinKill, Windows Media Player
exitapp
|
|
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
Posted: Wed Mar 17, 2010 6:52 am Post subject: |
|
|
Hi again Mike0627,
Sorry, didn't mean to confuse you with GUI. You didn't post your script and I just got gung-ho on wanting to help.
I intended it as a plug-and-go for you to use, but that was somewhat ill-mannered.
Looking at your script it appears you know what you want and you aren't doing anything weird, so why no go with yours?
I have 4 suggestions:
1) _After_ your "Do this now!" msgbox, add curly brackets and one command
| Code: | IfMsgBox, Cancel
{
WinClose, Windows Media Player
exitapp ; <------------------
}
|
in your loop with sleep and key wait
2) I don't believ that "ControlFocus, Windows Media Player" does anything, try commenting it out to confirm or prove me wrong.
3) Correct the "keywait" line to KeyWait, Enter
4) I agree with Tyrsius's "multiple line method" but not with his advice for using settimer.
Let us know how you fair.
Leef_me |
|
| Back to top |
|
 |
Mike0627
Joined: 13 Mar 2010 Posts: 4
|
Posted: Wed Mar 17, 2010 11:42 am Post subject: |
|
|
Thanks to all for your help. I think my brain is not wired right to understand this stuff, so I really appreciate all your time.
Here are my latest frustrations:
I need a way to stop the app from running. I was trying to use the escape key... but it doesn't matter what I use, I just need a way to terminte the app & shut it down whenever they want to. I have tried
| Code: |
; ESC::exitapp
; Hotkey, Escape
; ExitApp
;multiple line method (use when the key will execute more than one line of code)
; ESC::
; msgbox, You pressed the ESC key, the program will not exit.
; WinKill, Windows Media Player
; exitapp
|
They all just exit the app immediately when run... nothing happens but when I comment them out the script starts. So I need to learn what it is I am missing there... Are they positioned wrong? I have them at the start of the script.
#2 - When I manually send (one at a time) an ALT, a "p" and then an "ENTER" to WMP it will pause ... and then run when I send those same keystroke again. So I know that those keys can work. Actually so will a CONTROL+P - but I can't get that to work either
What I need is for the script to wait for an "ENTER" between those two instances. The timer runs - sends ALT, P, ENTER (to pause) -- then wait for an "ENTER" - send ALT, P, ENTER (to run). This code will not wait for the enter - it just loops and loops and loops. The sent keystrokes do work, but the pause is only for a millisecond. I have tried both ENTER and {ENTER} too....
| Code: |
loop
{
Sleep, (secs*1000) ;<------- this works every time
; ControlFocus, Windows Media Player
Send {Alt}
Send P
Send {ENTER} ; <----------- pauses for a millisecond or so
SoundBeep, ,1500]
KeyWait, Enter ; <-------------- this doesn't do anything
Send {Alt}
Send P
Send {ENTER} ; <------------- runs after the pause
} |
And of course there is no way to end it ...
Thanks again to all
Mike  |
|
| Back to top |
|
 |
OceanMachine
Joined: 15 Oct 2007 Posts: 780 Location: England
|
Posted: Wed Mar 17, 2010 3:47 pm Post subject: |
|
|
Hi Mike,
You will have to post your "Esc::ExitApp" outside the auto-execute section (i.e. after the first Return encountered at the top of your script), otherwise it will get executed when the script starts. Try putting them at the end of the script instead (after any returns).
Try the below, see if this helps:
| Code: | #NoEnv
SetTitleMatchMode, 2 ; match windows title more easily
secs := 5 ; will run every 5 seconds
SetTimer, PauseTimer, % secs*1000
Return ; this is the end of the auto-execute section
PauseTimer:
SetTimer, PauseTimer, off ; so it won't get interrupted by the timer while it is running
ControlSend,, ^p, Windows Media Player ; pause
SoundBeep, ,1500
KeyWait, Enter, D ; wait for enter to be pressed Down
ControlSend,, ^p, Windows Media Player ; unpause
SetTimer, PauseTimer, on ; restart the timer
Return
Esc::ExitApp ; exit when escape is pressed |
|
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5336 Location: San Diego, California
|
Posted: Wed Mar 17, 2010 9:24 pm Post subject: |
|
|
I took your full-script posting and modified it to work.
I carefully went through your code (this time) and found why it wouldn't pause the player reliably and why it wouldn't wait for Enter from user.
I still don't believe that " Send {ENTER}" is needed, but I left it.
I tested it with a version of Media Player Classic, and then corrected a few commands to work with WMP instead. You will find MPC specific lines commented out.
In case you didn't know the symbols "/*" and "*/" are a pair that makes writing extended comments (or disabling code) easier.
Since you wrote that you wanted it to close WMP when B.D.T. was closed, I added the OnExit command, which makes things a little simpler.
The Keywait command was coded wrong. The Options parameter was not included, which defaulted to 'wait for key released' which it was if the key wasn't being held. Sortof reverse catch-22.
| Code: | settitlematchmode 2 ; <--- allows easier title match
#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.
OnExit, quit ;<------------ funnel all requests to exit through this 'quit' subroutine
#SingleInstance force
; HotKey, Esc, on ; Assign a hotkey to terminate this script.
MsgBox, 4,Bretts DVD timer , This will start and run Bretts DVD timer program`n `nWould you like to continue?, 605 ; 60-second timeout.
IfMsgBox, No
ExitApp ; User pressed the "No" button.
InputBox, secs, Set Timer, Enter the number of seconds for the program to run between prompts?, , , 250 , 50 , , , 60 , 60
time=%secs%*1000
IfMsgBox Timeout, ExitApp
; check to see if player active
IfWinActive, Windows Media Player
WinMaximize ; Maximizes the window found by IfWinActive above.
Else run "C:\Program Files\Windows Media Player\wmplayer.exe" /open
Sleep 1000
/*======================================media player=========================
; check to see if player active
IfWinActive, Media Player
WinMaximize ; Maximizes the window found by IfWinActive above.
Else run "C:\Program Files\MPC HomeCinema\mpc-hc.exe"
Sleep 1000
======================================media player=========================
*/
; IfWinActive, Media Player
IfWinActive, Windows Media Player
MsgBox, 4145, Do This Now!!, While this window is up insert the DVD into the player and start it playing.`n `nThe DVD will play for %secs% seconds then pause for input.`n Once the DVD is playing select OK to start the timer. `nHitting "Cancel" will EXIT the program., 120
IfMsgBox, Cancel
ExitApp
******************************************************
******************************************************
; HERE IS WHERE MY NEXT CHALLENGE IS - THIS WILL WAIT THE RIGHT NUMBER OF SECONDS,
; AND SEND A SERIES OF COMMANDS THAT WIL PAUSE MEDIA PLAYER - THAT WORKS...
; KEYWAIT DOES NOT WORK... IT JUST SKIPS RIGHT BY IT
; I WANT THE PROGRAM TO PAUSE WHERE THE KEYWAIT IS ... AND WAIT FOR {ENTER}
; THEN RUN THE LOOP AGAIN....
;
; i ALSO NEED TO ASSIGN A HOTKEY SO {escape} WILL QUIT THE APP WHENEVER IT IS PRESSED.
; I TRIED A LINE FOR THAT UP TOP BUT IT DIDN'T WORK....
loop
{
Sleep, (secs*1000)
; ControlFocus, Windows Media Player
; Send {Alt} ;<---- this doesn't work well to send the characters separately
; Send P
send ^p ; normal way to send control-p // this should PAUSE the WMP
; send {space} ; media player classic
; some systems may be stubborn and require an alternate control-p
; for now this next line is commented out and will not be run
; send {control down} p {control down}
Send {ENTER}
SoundBeep, ,1500]
; KeyWait, {Enter}
KeyWait, Enter, D ; <--- wait for enter from user, this is the correct format of the command
send ^p ; normal way to send control-p // this should UNPAUSE the WMP
; send {space} ; normal way to send control-p // this should UNPAUSE the WMP
}
;=================== escape key closes the program ===========================
esc::
exitapp
;=================== if the program closes, so does WMP ======================
quit:
WinClose, Windows Media Player
;winclose, Media Player ; this is for Media Player Classic
exitapp
|
|
|
| Back to top |
|
 |
Mike0627
Joined: 13 Mar 2010 Posts: 4
|
Posted: Thu Mar 18, 2010 1:13 am Post subject: THANK YOU - THANK YOU |
|
|
I can not possibly thank each of you enough. I have finally come up with a version that works, pulling pieces and tips from everyone that helped.
I think I have it exactly as I need it. Compiled it to an exe file in a directory with the images I need Now I will be loading it on the schools computer, and probably making a few adjustments. Mission completed. I will be back if I need more help in the future.
Thank you all so much
Mike
[/img] |
|
| Back to top |
|
 |
evandevon
Joined: 22 Apr 2008 Posts: 82
|
Posted: Tue Mar 30, 2010 3:08 am Post subject: |
|
|
Hi Mike!
I´m a bit bummed that I missed assisting you on this script. I´m a special needs teacher and have made a similar script to work with VLC player. I salute you for giving it a go and doing it yourself, most parents I know can´t muster the energy to do something like this. If you ever need any help with any scripts, or have any ideas for new ones please let me know and I´d love to assist you to make something.
Something that could be added to your script pretty easily is to pause the movie, display a letter to the screen and your child must press the same letter on the keyboard to restart the movie. That would give a bit more of a challenge to your son if you think it is within his ability.
Here´s two of my apps which I´m quite proud of, I have a few others which I have not posted as yet if you´re interested. They are both free and open source so if you want to give them to your son´s school you´re more than welcome (in fact I would appreciate it).
MouseTrainer (my personal favourite)
http://www.autohotkey.com/forum/viewtopic.php?t=44948&highlight=mousetrainer
Typing Tutor
http://www.autohotkey.net/~evandevon/Typing%20Tutor%202.2.zip
There are animations that play as a reward in this app but I can´t remember if I uploaded them all. I´ll check when I get home and have access to my files.
Also, there are updates to both the programs which I have to upload and can´t at the moment but they still work (with only occassional bugs;) _________________ Inventing problems that need solutions...
Open Communicator
MouseTrainer |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|