Source codes as promised.
Again, all credit to ManaUser, my modified version of his script below:
Client
Code:
;AHK Remote Client v1.2
; written by ManaUser, Modified by me (Conquer)
#SingleInstance Force
#NoEnv
SendMode Input
NetworkAddress = 192.168.0.185 ;127.0.0.1 means local machine (so does blank).
NetworkPort = 8257
PromptForAddy = 1 ;Allows the user to supply another address if desired.
TestTimout = 300 ;ms, Blank means don't pre-test the address.
MaxDataLength = 4096 ;Longest message that can be recieved.
MaxGuiRows = 10
ButtonSize = 128 ;Blank means auto.
Menu TRAY, Tip, AHK Remote
Menu TRAY, Icon, SHELL32.DLL, 121
Menu TRAY, NoStandard
If (NOT A_IsCompiled)
{
Menu TRAY, Add, &Edit, TrayEdit
Menu TRAY, Add
}
Menu TRAY, Add, &Reload, TrayReload
Menu TRAY, Add, E&xit, TrayExit
If PromptForAddy
{
Gui Add, Text, w64 Right, Address:
Gui Add, Edit, w100 yp-4 x+8 vNetworkAddress, %NetworkAddress%
Gui Add, Text, xm w64 Right, Port:
Gui Add, Edit, w100 yp-4 x+8 vNetworkPort, %NetworkPort%
Gui Add, Button, gGetStarted Default, Connect
Gui Show,, Enter Address
Return
}
GetStarted:
Gui Submit
if (NetworkAddress = "")
NetworkAddress := "127.0.0.1"
If (NOT TestTimout)
TestTimout := 0
NeedIP := !RegExMatch(NetworkAddress, "^(\d+\.){3}\d+$")
If (TestTimout OR NeedIP)
{
;Use Ping to check if the address is reachable, we can also get the IP address this way.
RunWait %ComSpec% /C Ping -n 1 -w %TestTimout% %NetworkAddress% > getpingtestip.txt,, Hide
If (ErrorLevel AND TestTimout)
{
MsgBox,36,Connect, Computer didn't respond to ping - try anyways?
ifmsgbox no
{
FileDelete getpingtestip.txt
ExitApp
}
}
If NeedIP
{
Loop, Read, getpingtestip.txt
{
If RegExMatch(A_LoopReadLine, "(?<=\[)(\d+\.){3}\d+(?=\])", NetworkAddress)
Break
}
}
FileDelete getpingtestip.txt
}
Menu PopUp, Add, Dummy, HandleMenu ;So the menu exists.
If (ButtonSize != "")
ButtonSize := "w" . ButtonSize
;v v v v v v v v v v v v v v v v v v v
OnExit DoExit
MainSocket := PrepareSocket(NetworkAddress, NetworkPort)
If (MainSocket = -1)
ExitApp ;failed
DetectHiddenWindows On
Process Exist
MainWindow := WinExist("ahk_class AutoHotkey ahk_pid " . ErrorLevel)
DetectHiddenWindows Off
;^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
;FD_READ + FD_CLOSE + FD_WRITE = 35
If DllCall("Ws2_32\WSAAsyncSelect", "UInt", MainSocket, "UInt", MainWindow, "UInt", 5555, "Int", 35)
;v v v v v v v v v v v v v v v v v v v
{
MsgBox % "WSAAsyncSelect() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
ExitApp
}
OnMessage(5555, "ReceiveData", 99) ;Allow 99 (i.e. lots of) threads.
Return
PrepareSocket(IPAddress, Port)
{
VarSetCapacity(wsaData, 32)
Result := DllCall("Ws2_32\WSAStartup", "UShort", 0x0002, "UInt", &wsaData)
If ErrorLevel
{
MsgBox WSAStartup() could not be called due to error %ErrorLevel%. Winsock 2.0 or higher is required.
return -1
}
If Result ; Non-zero, which means it failed (most Winsock functions return 0 upon success).
{
MsgBox % "WSAStartup() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
;AF_INET = 2 SOCK_STREAM = 1 IPPROTO_TCP = 6
Socket := DllCall("Ws2_32\socket", "Int", 2, "Int", 1, "Int", 6)
If (Socket = -1)
{
MsgBox % "Socket() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
VarSetCapacity(SocketAddress, 16)
InsertInteger(2, SocketAddress, 0, 2) ; AF_INET = 2
InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2) ; sin_port
InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), SocketAddress, 4, 4) ; sin_addr.s_addr
;^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
If DllCall("Ws2_32\connect", "UInt", Socket, "UInt", &SocketAddress, "Int", 16)
{
Result := DllCall("Ws2_32\WSAGetLastError")
If (Result = 10061)
MsgBox,16,Lan Remote,Laptop denied connect.
Else
MsgBox,16,Lan Remote,Problem connecting (%Result%)
return -1
}
Return Socket
}
ReceiveData(wParam, lParam)
{
Global MaxGuiRows, ButtonSize, MaxDataLength, MainSocket, MenuChoice
;v v v v v v v v v v v v v v v v v v v
VarSetCapacity(ReceivedData, MaxDataLength, 0)
ReceivedDataLength := DllCall("Ws2_32\recv", "UInt", wParam, "Str", ReceivedData, "Int", MaxDataLength, "Int", 0)
If (ReceivedDataLength = 0) ; The connection was gracefully closed
Return NormalClose()
if ReceivedDataLength = -1
{
WinsockError := DllCall("Ws2_32\WSAGetLastError")
If (WinsockError = 10035) ; No more data to be read
Return 1
If WinsockError = 10054 ; Connection closed
Return NormalClose()
MsgBox % "Recv() indicated Winsock error " . WinsockError
ExitApp
}
Command := SubStr(ReceivedData, 1, 10)
ReceivedData := SubStr(ReceivedData, 11)
;^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
If (Command = "ARCOMLIST:")
{
Gui Destroy
/*
Loop Parse, ReceivedData, %A_Space%
{
StringReplace ButtonName, A_Loopfield, _, %A_Space%, All
If (Mod(A_Index, MaxGuiRows) = 0)
Options .= "ym "
ifinstring buttonname, newcolumn
{
options = x+5 y5
continue ; Don't add a button that says 'newcolumn'
}
Gui Add, Button, %ButtonSize% gHandleButton %Options%, %ButtonName%
Options =
}
*/
Gui, Add, Button, x142 y13 w40 h37 gmedia_playpause, >/ll
Gui, Add, Button, x112 y14 w30 h30 gmedia_prev, <<
Gui, Add, Button, x182 y13 w30 h30 gmedia_next, >>
Gui, Add, Button, x6 y10 w75 h25 gHandleButton, Play Song
Gui, Add, Button, x6 y+1 w75 h25 gHandleButton, Menu
Gui, Add, GroupBox, x92 y0 w150 h80 , iTunes
Gui, Add, GroupBox, x242 y0 w115 h80 , YouTube
;Gui, Add, Button, x252 y20 w100 h30 gHandleButton, Search Song
Gui, Add, Button, x252 y20 w95 h25 gHandleButton, Open URL
Gui, Add, Button, y+1 w95 h25 gclose_url, Stop Playback
Gui, Add, Slider, x102 y50 w130 h20 gset_volume vVol_Bar, 0
Gui, +0x80000 -0x10000 ; -0x20000
Gui, Add, StatusBar,,
SB_SetText("Connected to speaker comp.")
Gui, Show,h107 w362, LAN Remote
}
Else If (Command = "ARSHOWTXT:")
{
Gui 2:Destroy
Gui 2:Add, Edit, Multi w500, %ReceivedData%
Gui 2:+ToolWindow +Owner1
Gui 2:Show,, AHK Remote
}
Else If (Command = "ARMESSAGE:")
{
Gui +OwnDialogs
SB_SetText("[" . A_Hour . ":" . A_Min . ":" . A_Sec . "]: " . ReceivedData)
}
Else If (Command = "ARYESORNO:")
{
Gui +OwnDialogs
MsgBox 36, AHK Remote, %ReceivedData%
IfMsgBox Yes
SendData(MainSocket, "ARESPONSE:YES")
Else
SendData(MainSocket, "ARESPONSE:NO")
}
Else If (Command = "ARGETINFO:")
{
Gui +OwnDialogs
InputBox Result, AHK Remote, %ReceivedData%,,, 130
If (ErrorLevel OR Result = "")
SendData(MainSocket, "ARESPONSE:CANCEL")
Else
SendData(MainSocket, "ARESPONSE:" . Result)
}
Else If (Command = "ARPASWORD:")
{
Gui +OwnDialogs
InputBox Result, AHK Remote, Password required., Hide,, 110
If ErrorLevel
SendData(MainSocket, "ARESPONSE:CANCEL")
Else
SendData(MainSocket, "ARESPONSE:" . RC4txt2hex("OPENSESAME", Result . ReceivedData))
}
Else If (Command = "ARPOPMENU:")
{
Menu PopUp, DeleteAll
Loop Parse, ReceivedData, |
Menu PopUp, Add, %A_LoopField%, HandleMenu
MenuChoice := 0
Menu PopUp, Show
SendData(MainSocket, "ARESPONSE:" . MenuChoice)
}
Else if (Command = "ArVolRefr:")
guicontrol,,vol_bar,%ReceivedData%
Return 1
}
NormalClose()
{
Msgbox,20,Remote,Laptop Disconnected.`n`nReload? `n`nHit No/hit nothing to exit,5
ifmsgbox yes
reload
else
ExitApp
Return 1
}
;v v v v v v v v v v v v v v v v v v v
SendData(Socket, Data)
{
SendRet := DllCall("Ws2_32\send", "UInt", Socket, "Str", Data, "Int", StrLen(Data), "Int", 0)
If (SendRet = -1)
MsgBox % "Send() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
sleep 200
Return SendRet
}
;By Laszlo, used by the password function.
RC4txt2hex(Data,Pass) {
Format := A_FormatInteger
SetFormat Integer, Hex
b := 0, j := 0
VarSetCapacity(Result,StrLen(Data)*4)
Loop 256 {
a := A_Index - 1
Key%a% := Asc(SubStr(Pass, Mod(a,StrLen(Pass))+1, 1))
sBox%a% := a
}
Loop 256 {
a := A_Index - 1
b := b + sBox%a% + Key%a% & 255
T := sBox%a%
sBox%a% := sBox%b%
sBox%b% := T
}
Loop Parse, Data
{
i := A_Index & 255
j := sBox%i% + j & 255
k := sBox%i% + sBox%j% & 255
Result .= Asc(A_LoopField)^sBox%k%
}
Result := RegExReplace(Result, "0x(.)(?=0x|$)", "0$1")
StringReplace Result, Result, 0x,,All
SetFormat Integer, %Format%
Return Result
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
{
Loop %pSize% ; Copy each byte in the integer into the structure as raw binary data.
DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}
GuiClose:
ExitApp
DoExit:
TrayExit:
DllCall("Ws2_32\WSACleanup")
ExitApp
TrayEdit:
Edit
Return
TrayReload:
Reload
Return
;^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
HandleButton:
StringReplace CommandName, A_GuiControl, %A_Space%, _, All
SendData(MainSocket, "ARCOMMAND:" . CommandName)
Return
media_playpause:
media_next:
media_prev:
close_url:
SendData(MainSocket, "ARCOMMAND:" . a_thislabel)
return
set_volume:
gui,submit,nohide
senddata(mainsocket,"ARSETVOLU:" . vol_bar)
return
HandleMenu:
MenuChoice := A_ThisMenuItemPos
Return
Server
Code:
;AHK Remote Server v2
; written by ManaUser, modified by me (Conquer/Dorian/Tiler), too many nicknames :p)
; link to original post should be in the post.
; firefox path - specify absolute path to firefox.exe
firefox_path = C:\Program Files (x86)\Mozilla Firefox\firefox.exe
; itunes path - specify absolute path to itunes.exe
itunes_path = C:\Program Files (x86)\iTunes\iTunes.exe
; music library path - all your mp3s should be in here. best to use itunes media dir
media_dir = C:\Users\Tyler\Music
; network/listen address - configure as needed
NetworkAddress = 192.168.0.185 ;Listen address, 0.0.0.0 = any
NetworkPort = 8257 ;Listen port
; End of configuration section - changing anything past this point voids your warranty :p
#SingleInstance Force
#NoEnv
;#Notrayicon
sleep 1000
SendMode Input
settitlematchmode,2
setkeydelay,-1
setwindelay,-1
setcontroldelay,-1
setbatchlines,-1
MaxDataLength = 4096 ;Longest message that can be recieved.
Menu TRAY, Tip, AHK Remote Server`n%A_IPAddress1%
Menu TRAY, Icon, SHELL32.DLL, 125
Menu TRAY, NoStandard
; NewColumn(x) means force new column
If A_IsCompiled
CommandList = Volume_Up Volume_Down Mute NewColumn Open_Youtube_URL
Else
{
LabelStart := False
Loop Read, %A_ScriptFullPath%
{
If (NOT LabelStart)
{
If InStr(A_LoopReadLine, "===" . "Begin Custom Labels" . "===")
LabelStart := True
Else
Continue
}
If RegExMatch(A_LoopReadLine, "^[^\s;]\S*(?=:\s*$)", LabelName)
CommandList .= " " . LabelName
}
CommandList := SubStr(CommandList, 2)
Menu TRAY, Add, &Edit, TrayEdit
Menu TRAY, Add, &Copy Command List, TrayCopy
Menu TRAY, Add
}
Menu TRAY, Add, No Connection, TrayDisconnect
Menu TRAY, Disable, No Connection
Menu TRAY, Add, &Reload, TrayReload
Menu TRAY, Add, E&xit, TrayExit
RunningCommands := " "
;v v v v v v v v v v v v v v v v v v v
OnExit DoExit
MainSocket := PrepareSocket(NetworkAddress, NetworkPort)
If (MainSocket = -1)
ExitApp ;failed
DetectHiddenWindows On
Process Exist
MainWindow := WinExist("ahk_class AutoHotkey ahk_pid " . ErrorLevel)
DetectHiddenWindows Off
;^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
;FD_READ + FD_CLOSE + FD_ACCEPT = 41
If DllCall("Ws2_32\WSAAsyncSelect", "UInt", MainSocket, "UInt", MainWindow, "UInt", 5555, "Int", 41)
;v v v v v v v v v v v v v v v v v v v
{
sleep 2000
reload
ExitApp
}
OnMessage(5555, "ReceiveData", 99) ;Allow 99 (i.e. lots of) threads.
Return
PrepareSocket(IPAddress, Port)
{
VarSetCapacity(wsaData, 32)
Result := DllCall("Ws2_32\WSAStartup", "UShort", 0x0002, "UInt", &wsaData)
If ErrorLevel
{
MsgBox WSAStartup() could not be called due to error %ErrorLevel%. Winsock 2.0 or higher is required.
return -1
}
If Result ; Non-zero, which means it failed (most Winsock functions return 0 upon success).
{
MsgBox % "WSAStartup() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
;AF_INET = 2 SOCK_STREAM = 1 IPPROTO_TCP = 6
Socket := DllCall("Ws2_32\socket", "Int", 2, "Int", 1, "Int", 6)
If (Socket = -1)
{
MsgBox % "Socket() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
VarSetCapacity(SocketAddress, 16)
InsertInteger(2, SocketAddress, 0, 2) ; AF_INET = 2
InsertInteger(DllCall("Ws2_32\htons", "UShort", Port), SocketAddress, 2, 2) ; sin_port
InsertInteger(DllCall("Ws2_32\inet_addr", "Str", IPAddress), SocketAddress, 4, 4) ; sin_addr.s_addr
;^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
If DllCall("Ws2_32\bind", "UInt", Socket, "UInt", &SocketAddress, "Int", 16)
{
MsgBox % "Bind() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
If DllCall("Ws2_32\listen", "UInt", Socket, "UInt", "SOMAXCONN")
{
MsgBox % "Listen() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
return -1
}
Return Socket
}
ReceiveData(wParam, lParam)
{
Global MaxDataLength, OutgoingSocket, CommandList, RunningCommands, ClientResponse
Event := lParam & 0xFFFF
If (Event = 8) ;FD_ACCEPT = 8
{
If (OutgoingSocket > 0)
NormalClose() ;Close OutgoingSocket
OutgoingSocket := DllCall("Ws2_32\accept", "UInt", wParam, "UInt", &SocketAddress, "Int", 0)
If (OutgoingSocket < 0)
MsgBox % "Accept() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
Else
{
SendData(OutgoingSocket, "ARCOMLIST:" . CommandList)
settimer, refresh_volume, 5000
Menu TRAY, Rename, No Connection, &Disconnect
Menu TRAY, Enable, &Disconnect
Menu TRAY, Tip, AHK Remote Server`nConnected!
}
Return 1
}
;v v v v v v v v v v v v v v v v v v v
VarSetCapacity(ReceivedData, MaxDataLength, 0)
ReceivedDataLength := DllCall("Ws2_32\recv", "UInt", wParam, "Str", ReceivedData, "Int", MaxDataLength, "Int", 0)
If (ReceivedDataLength = 0) ; The connection was gracefully closed
Return NormalClose()
if ReceivedDataLength = -1
{
WinsockError := DllCall("Ws2_32\WSAGetLastError")
If (WinsockError = 10035) ; No more data to be read
Return 1
If WinsockError = 10054 ; Connection closed
Return NormalClose()
Reload ; unknown error, just reload.
return
}
Command := SubStr(ReceivedData, 1, 10)
ReceivedData := SubStr(ReceivedData, 11)
;^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
If (Command = "ARCOMMAND:")
{
If InStr(" " . CommandList . " ", " " . ReceivedData . " ")
{
If NOT InStr(" " . RunningCommands . " ", " " . ReceivedData . " ")
{
RunningCommands .= ReceivedData . " "
If IsLabel(ReceivedData) ;Should be redundant, but just in case.
GoSub %ReceivedData%
StringReplace, RunningCommands, RunningCommands, %A_Space%%ReceivedData%%A_Space%, %A_Space%
}
}
} else If (Command = "ARESPONSE:")
ClientResponse := ReceivedData
else if (Command = "ARSETVOLU:")
{
soundset, %receiveddata%
gosub refresh_volume
}
Return 1
}
NormalClose()
{
Global OutgoingSocket, ClientResponse := "DISCONNECT"
Result := DllCall("Ws2_32\closesocket", "UInt", OutgoingSocket)
If (Result != 0)
{
sleep 200
reload
}
OutgoingSocket =
Menu TRAY, Tip, AHK Remote Server`n%A_IPAddress1%
Menu TRAY, Rename, &Disconnect, No Connection
settimer,refresh_volume,off
Menu TRAY, Disable, No Connection
Return 1
}
;v v v v v v v v v v v v v v v v v v v
SendData(Socket, Data)
{
SendRet := DllCall("Ws2_32\send", "UInt", Socket, "Str", Data, "Int", StrLen(Data), "Int", 0)
If (SendRet = -1)
MsgBox % "Send() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError")
sleep 200 ; prevent problems with connection freezing etc
Return SendRet
}
;By Laszlo, used by the password function.
RC4txt2hex(Data,Pass) {
Format := A_FormatInteger
SetFormat Integer, Hex
b := 0, j := 0
VarSetCapacity(Result,StrLen(Data)*4)
Loop 256 {
a := A_Index - 1
Key%a% := Asc(SubStr(Pass, Mod(a,StrLen(Pass))+1, 1))
sBox%a% := a
}
Loop 256 {
a := A_Index - 1
b := b + sBox%a% + Key%a% & 255
T := sBox%a%
sBox%a% := sBox%b%
sBox%b% := T
}
Loop Parse, Data
{
i := A_Index & 255
j := sBox%i% + j & 255
k := sBox%i% + sBox%j% & 255
Result .= Asc(A_LoopField)^sBox%k%
}
Result := RegExReplace(Result, "0x(.)(?=0x|$)", "0$1")
StringReplace Result, Result, 0x,,All
SetFormat Integer, %Format%
Return Result
}
InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
{
Loop %pSize% ; Copy each byte in the integer into the structure as raw binary data.
DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}
GuiClose:
ExitApp
refresh_volume: ; when connected, send client volume level every 5 sec
SoundGet, outvar
senddata(outgoingSocket,"ARVolRefr:" . round(outvar))
return
DoExit:
TrayExit:
DllCall("Ws2_32\WSACleanup")
ExitApp
TrayEdit:
Edit
Return
TrayReload:
Reload
Return
;^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
TrayCopy:
ClipBoard := CommandList
Return
TrayDisconnect:
NormalClose()
Return
; ---------------------------------------------------------------------------
; Here are some functions you can use to communicate with the client script.
ARMessage(Text) ;Standard message box.
{
Global OutgoingSocket
SendData(OutgoingSocket, "ARMESSAGE:" . Text)
}
ARShowText(Text) ;Shows text in a copyable box, for longer test.
{
Global OutgoingSocket
SendData(OutgoingSocket, "ARSHOWTXT:" . Text)
}
ARYesNo(Text) ;Returns 1 (true) for yes.
{
Global OutgoingSocket, ClientResponse =
SendData(OutgoingSocket, "ARYESORNO:" . Text)
Loop
{
Sleep 50
If (ClientResponse == "DISCONNECT")
Exit
Else If (ClientResponse != "")
Return (ClientResponse == "YES")
}
}
ARInput(Text) ;Returns CANCEL if response is blank or dialog is canceled.
{
Global OutgoingSocket, ClientResponse =
SendData(OutgoingSocket, "ARGETINFO:" . Text)
Loop
{
Sleep 50
If (ClientResponse == "DISCONNECT")
Exit
Else If (ClientResponse != "")
Return ClientResponse
}
}
ARPassword(Pass) ;Asks for a password .
{ ;Returns 1 (true) for success. If ErrorLevel is 1, it was canceled.
Global OutgoingSocket, ClientResponse =
Loop 10
{
Random Rand, 1, 255
Challenge .= Chr(Rand)
}
SendData(OutgoingSocket, "ARPASWORD:" . Challenge)
Loop
{
Sleep 50
If (ClientResponse == "DISCONNECT")
Exit
Else If (ClientResponse != "")
{
If (ClientResponse = "CANCEL")
{
ErrorLevel := 1
Return 0
}
ErrorLevel := 0
Return (ClientResponse = RC4txt2hex("OPENSESAME", Pass . Challenge))
}
}
}
ARMenu(Items) ;Items format: Item1|Item2|Item3, || makes a separator.
{ ;Returns item postion (counting separators) or 0 if canceled.
Global OutgoingSocket, ClientResponse =
SendData(OutgoingSocket, "ARPOPMENU:" . Items)
Loop
{
Sleep 50
If (ClientResponse == "DISCONNECT")
Exit
Else If (ClientResponse != "")
Return ClientResponse
}
}
; ==========Begin Custom Labels========== (Do not delete this line.)
; Put a comment after a label to prevent it from being a command.
Close_Server:
If ARYesNo("Are you sure?")
ExitApp
Return
Restart_Server:
Reload
Return
Chat:
Result := ARInput("Send message:")
if result = cancel
return
Loop
{
If (Result == "CANCEL")
Break
InputBox Result, AHK Remote Server, %Result%,,, 130
If ErrorLevel
Break
Result := ARInput(Result)
}
return
Shutdown_Computer:
ARPassword := ARInput("Password ?")
If ARPassword("swordfish")
{
MsgBox 49, AHK Remote Server, AHK Remote Client requested shutdown. Permit?, 20
IfMsgBox OK
Shutdown 12
Else
ARMessage("Shutdown aborted by remote user.")
}
Else
ARMessage("Permission Denied.")
Return
play_song:
kindafound =
UserInput := ARInput("Enter Song Name")
if userinput = cancel
{
armessage("Cancelled")
return
}
ArMessage("Searching for song in itunes lirary..")
Loop, %media_dir%\*.*, 1, 1
{
mp3 = %A_LoopFileFullPath%
Found = Yes
Loop, Parse, UserInput, %a_space%
IfNotInString, mp3, %A_LoopField%, SetEnv, Found, No
{
IfEqual, Found, Yes
{
Ifnotinstring, mp3,.mp3 Ifinstring, mp3,., , break
{
if ARYesNo("Play '" . mp3 . "' ??")
{
kindafound++
run, %itunes_path% "%mp3%",,useerrorlevel
ArMessage("Playing " . mp3)
}
else
{
kindafound++
if ARYesNo("Play through YouTube instead?")
{
autourl = 1
gosub open_url_auto
autourl = 0
}
else
ArMessage("Cancelled.")
}
Found = No
break
}
}
}
}
if kindafound =
{
if ARYesNo("Not found in iTunes - Search YouTube for '" . userinput . "' ??'")
{
autourl = 1
gosub open_url_auto
autourl = 0
}
else
ArMessage("Cancelled.")
}
return
set_volume:
level := ARInput("Enter volume %:")
soundsetwavevolume,%level%
return
Menu:
Result := ARMenu("Close Server|Restart Server|Shutdown Computer||Chat||Mute/Unmute")
If (Result = 1)
goto close_server
Else If (Result = 2)
goto restart_server
Else If (Result = 3)
goto shutdown_computer
Else If (Result = 5)
goto chat
else if (result = 7)
goto Mute
Return
media_prev:
IfWinExist, ahk_class iTunes
{
armessage("Itunes > Media Previous")
ControlSend, ahk_parent, ^{left}
}
else
{
armessage("Keyboard > Media Previous")
send {Media_prev}
}
return
media_next:
IfWinExist, ahk_class iTunes
{
armessage("Itunes > Media Next")
ControlSend, ahk_parent, ^{right}
}
else
{
armessage("Keyboard > Media Next")
send {Media_next}
}
return
media_playpause:
IfWinExist, ahk_class iTunes
{
armessage("Itunes > Media Play/Pause")
ControlSend, ahk_parent, {space}
}
else
{
armessage("Keyboard > Media Play/Pause")
send {Media_play_pause}
}
return
Mute:
SoundSet, +1, , mute ; toggle mute
return
Open_url:
gosub close_url
result := ARInput("Enter URL to open")
ifnotinstring, result, www.youtube.com
{
arMessage("Only Youtube allowed")
return
}
open_url_auto:
if userinput
{
result := userinput
userinput =
}
if result = cancel
return
ARMessage("Opening URL..")
ifwinexist, Mozilla Firefox ; mozilla firefox already running
{
detecthiddenwindows, off
firefox_windows_cache =
loop 10
{
ifwinexist, Mozilla Firefox
{
winget,firefox_id,id
winhide Mozilla Firefox ; hide all existing firefox windows
firefox_windows_cache .= "|" . firefox_id
}
ifwinnotexist Mozilla Firefox
break
}
}
errorlevelz =
if autourl = 1
{
stringreplace,result,result,%A_space%,+,A
run, %firefox_path% "http://www.google.com/search?q=youtube.com "%result%"&btnI=Im+Feeling+Lucky",C:\Program Files (x86)\Mozilla Firefox\,useerrorlevel,mozilla_id
autourl = 0
errorlevelz := errorlevel
}
else
{
run firefox.exe %result%,,userrorlevel
errorlevelz := errorlevel
}
if errorlevelz
ARMessage("Couldn't open it - link broken?")
else
{
ARMessage("Opened Youtube url.")
winwait, Mozilla Firefox
WinGet, firefox_id , id, Mozilla Firefox
lastwindow := firefox_id
}
if firefox_windows_cache
{
detecthiddenwindows, on
loop, parse, firefox_windows_cache, |
winshow, Mozilla Firefox ahk_id %a_loopfield%
firefox_windows_cache =
}
return
close_url:
ARMessage("Closing Old URL..")
winkill ahk_id %firefox_id%,,5
ifwinexist ahk_id %firefox_id%
{
if A_TimeIdlePhysical > 30000 ; no one has touched keybd/mouse in 30 sec, someone prob isn't using the comp, kill the process.
winget,firefox_process,processname,ahk_id %firefox_id%
process,close,ahk_id %firefox_process%
}
return