Sign in to follow this  
Followers 0
WesleyC

HotKeySet issues

12 posts in this topic

I'm newly returning to AutoIt after ... I don't know how long a departure, but several years at least. Long enough that I barely remember anything about it.

I'm trying to write a little wrapper around mplayer that allows me to use hot keys to control playback (like winamp does, but without winamp). It's the first step to a larger process. I'm running into an issue that appears to be a bug but, as I've only started playing with AutoIt recently, it could just as easily be me not understanding something.

The script works, except for the hot key. It starts mplayer on startup like I want, and stops it on shutdown like I want. I just cannot get ctrl-alt-shift-c to pause mplayer, unless I add a sleep() or msgbox() to the function as below:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate("MP3 Player", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUICtrlCreateLabel("CTRL+ALT+SHIFT+C = Play/Pause", 30, 10)
GUISetState(@SW_SHOW)

HotKeySet ( "^!+c", "SendASpace" )

Run('mplayer -shuffle -playlist d:\music\music.m3u', "d:\music", @SW_HIDE)

While 1
  Sleep(10)
WEnd

Func CLOSEClicked()
  ControlSend("d:\util\mplayer.exe", "", "", "q")
  Exit
EndFunc

Func SendASpace()
    ;Sleep(1000)
    ControlSend("d:\util\mplayer.exe", "", "", " ")
EndFunc

This code, as is, will not pause mplayer.

If I remove the ; from the 3rd from final line (;Sleep(1000)) it will pause it, after a 1 second wait.

If I change the 1000 to 100, it again won't pause the music.

Any ideas? I was really happy to see how easy this was, until I hit this snag.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try

HotKeySet("^!+{c}", "SendASpace")

I think that will do the trick :D

*** EDIT ***

Sorry, I didn't recognize the problem, this probably won't do the trick :oops:

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

Thanks for the reply! Sadly, it did not help. The { } around the C made no change to the way the script is acting. It still fails without the sleep(1000) and still pauses with the sleep(1000) present.

Share this post


Link to post
Share on other sites

Sorry, i can't understand why you used ControlSend() this way?

ControlSend("d:utilmplayer.exe", "", "", " ")

What is d:utilmplayer.exe ? ( Maybe it's just an example code! )

BTW, if you want to send Space use it like this:

"{SPACE}"

Share this post


Link to post
Share on other sites

d:\util\mplayer.exe is the title of the window, yes. I know it works because it works for other key strokes.

I fiddled a bit more, and if I leave out "ctrl" it works. The below code does exactly what I want, except I hit "alt-shift-c" instead of "ctrl-alt-shift-c". Note, the ONLY difference between this and my original code is that I left out the "^" symbol.

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate("MP3 Player", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUICtrlCreateLabel("CTRL+ALT+SHIFT+C = Play/Pause", 30, 10)
GUISetState(@SW_SHOW)

HotKeySet ( "!+c", "SendASpace" )

Run('mplayer -shuffle -playlist d:\music\music.m3u', "d:\music", @SW_HIDE)

While 1
  Sleep(10)
WEnd

Func CLOSEClicked()
  ControlSend("d:\util\mplayer.exe", "", "", "q")
  Exit
EndFunc

Func SendASpace()
    ;Sleep(1000)
    ControlSend("d:\util\mplayer.exe", "", "", " ")
EndFunc

The problem does NOT seem to have anything to do with ControlSend and seems to have everything to do with HotKeySet.

Share this post


Link to post
Share on other sites

Scratch that last paragraph. Everything else is correct, but it does seem to have to do with ControlSend.

When I set it up with a simpler example:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate("MP3 Player", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUICtrlCreateLabel("Notepad Test", 30, 10)
GUISetState(@SW_SHOW)

HotKeySet ( "^!+c", "CtrlAltShiftTest" )
HotKeySet ( "!+c", "AltShiftTest" )

Run("notepad.exe")

While 1
  Sleep(10)
WEnd

Func CLOSEClicked()
  Exit
EndFunc

Func CtrlAltShiftTest()
    Send("Ctrl-Alt-Shift worked!      ")
EndFunc

Func AltShiftTest()
    Send("Alt-Shift worked!     ")
EndFunc

Both work.

But still, when I don't use the CTRL code "^" and hit alt-shift-c, mplayer pauses (what it would do if you hit space) so the code *works*

Share this post


Link to post
Share on other sites

I am also new to Autoit and noticed the same behavior. I looked through the forum for hotkey issues. After running some simple test scripts the problem seems to be related to the script executing another Ctrl and Alt with the keys still pressed when you triggered the script with the original Ctrl and/or Alt sequence - not always precisely reproducible.

I had to add a Sleep() after each Ctrl or Alt - I found Sleep(500) worked on my box but may vary for each.

If there is a more elegant solution, I would love to know it.

I already checked Sticky Keys

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
HotKeySet ( "^!c", "CtrlAltTest" )
HotKeySet ( "!c", "AltTest" )
Run("notepad.exe")
While 1
  Sleep(10)
WEnd

Func CtrlAltTest()
    Send("Ctrl-Alt-Shift worked!      ")
EndFunc
Func AltTest()
    Send("Alt-Shift worked!  ")
EndFunc

Share this post


Link to post
Share on other sites

I opted to just ignore ctrl. Nothing I can think of uses alt-shift-key hotkeys, so that works fine for me.

Thanks everybody for your help on this. I appreciate the effort! :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0