HTTP Get unresponsive after a few key presses

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
etc6849
Posts: 4
Joined: 19 Mar 2018, 21:01

HTTP Get unresponsive after a few key presses

19 Mar 2018, 21:08

I'm trying to remap the volume up key under Windows 10 to send a URL to my home automation server (simple authentication, e.g. username and password embedded in http URL).

The first few presses work, then the script quits working?

Code: Select all

Volume_Up::
oHttp := ComObjCreate("Msxml2.XMLHTTP")
oHttp.open("GET","http://UserName:[email protected]/sys/devices/customdevices/OSC?d??VolumeUp")
oHttp.send()
Any ideas/help is much appreciated. The code above is all the code I have in the ahk file right now, but eventually I want to add Volume_Down and Volume_Mute keys as well.
etc6849
Posts: 4
Joined: 19 Mar 2018, 21:01

Re: HTTP Get unresponsive after a few key presses

19 Mar 2018, 21:33

Ok, so it appears the answer is my syntax is correct and the issue is with my home automation server's code :)

I stupidly thought that not having my server send a response would let things work faster. Now I have I added code to my VolumeUp method on my home automation server so that the response body has some text (instead of containing nothing). Works great now and all it needed to return is a single line of text.
Last edited by etc6849 on 19 Mar 2018, 22:22, edited 1 time in total.
etc6849
Posts: 4
Joined: 19 Mar 2018, 21:01

Re: HTTP Get unresponsive after a few key presses

19 Mar 2018, 21:36

Ok, just in case anyone ever uses my code, I also added the recommended stuff at the top, along with a sleep of 60 ms so as to give my home automation server a break and not fill up its queue.

QUESTION: How to do code like this for the other buttons in same file? Right now, I have everything working, but I had to make a file for mute and another file for volume_down. I assume this has to do with threading and my code having an issue, but it works, just seems three files should be unnecessary. Any ideas?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
Volume_Up::
oHttp := ComObjCreate("Msxml2.XMLHTTP")
oHttp.open("GET","http://username:[email protected]/sys/devices/customdevices/OSC?d??VolumeUp")
oHttp.send()
sleep, 60
return
Last edited by etc6849 on 19 Mar 2018, 23:53, edited 1 time in total.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: HTTP Get unresponsive after a few key presses

19 Mar 2018, 23:36

try:

Code: Select all

Volume_Up::HttpSend("VolumeUp")
Volume_Down::HttpSend("VolumeDown")
Volume_Mute::HttpSend("VolumeMute")

HttpSend(Action) {
	oHttp := ComObjCreate("Msxml2.XMLHTTP")
	oHttp.open("GET","http://username:[email protected]/sys/devices/customdevices/OSC?d??" Action)
	oHttp.send()
	sleep, 60
}
etc6849
Posts: 4
Joined: 19 Mar 2018, 21:01

Re: HTTP Get unresponsive after a few key presses

19 Mar 2018, 23:55

Please edit your post as I posted something I shouldn't have, like a pw lol...

PS: works great thanks! I think the issue is you can't have multiple XMLHTTP objects (because I did try two objects before with different names)?
tmplinshi wrote:try:

Code: Select all

Volume_Up::HttpSend("VolumeUp")
Volume_Down::HttpSend("VolumeDown")
Volume_Mute::HttpSend("VolumeMute")

HttpSend(Action) {
	oHttp := ComObjCreate("Msxml2.XMLHTTP")
	oHttp.open("GET","http://user:[email protected]/sys/devices/customdevices/OSC?d??" Action)
	oHttp.send()
	sleep, 60
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 272 guests