Jump to content
LaunchBox Community Forums
darthopus

[Partial solution] AutoHotKey and checking which display is being used

Recommended Posts

Posted (edited)

I am using a wonderful script, written by ChadMondo on this forum, for using the Home button on an Xbox One Controller to launch and close BigBox. It works perfectly. The code can be found here:

https://forums.launchbox-app.com/topic/42319-ahk-script-for-windows-10-use-center-guide-button-to-open-big-box-hold-button-down-to-turn-off-controller/

I am trying to adapt it to change between two monitors. It works for switching to the second monitor, but will not work for switching back.

Here is the code. I'm pretty sure it is the #IfWinNotExist and #ifWinActive lines that are giving me the trouble since they look to see if a window exists/not exists. I've looked at the documentation and cannot seem to find how to have autohotkey determine which monitor is being used.

Any ideas?

#IfWinNotExist, LaunchBox Big Box
$vk07sc000::
aDown:=A_TickCount
While GetKeyState("vk07sc000")
Duration:=(A_TickCount-aDown)
If (Duration<300)
run %windir%\System32\DisplaySwitch.exe /external

Else
{}
Return

#IfWinActive, LaunchBox Big Box
$vk07sc000::
aDown:=A_TickCount
While GetKeyState("vk07sc000")
Duration:=(A_TickCount-aDown)
If (Duration<300)
run %windir%\System32\DisplaySwitch.exe /internal
Else
{}
Return

 

Edited by darthopus
Partially Solved

Share this post


Link to post
Share on other sites

I was able to get something together that works for me. There is probably a better way to do it, but this works.

#IfWinNotActive, LaunchBox Big Box
$vk07sc000::
run %windir%\System32\DisplaySwitch.exe /external
  Run, mmsys.cpl 
  WinWait,Sound ; Change "Sound" to the name of the window in your local language 
  ControlSend,SysListView321,{Down 3} ; This number selects the matching audio device in the list, change it accordingly 
  ControlClick,&Set Default ; Change "&Set Default" to the name of the button in your local language 
  ControlClick,OK
  Send, ^!o
aDown:=A_TickCount
While GetKeyState("vk07sc000")
Duration:=(A_TickCount-aDown)
If (Duration<300)
run "G:\LaunchBox\BigBox.exe"
Else
{}
Return




#IfWinActive, LaunchBox Big Box
$vk07sc000::
aDown:=A_TickCount
While GetKeyState("vk07sc000")
Duration:=(A_TickCount-aDown)
If (Duration<300)
send, x
Else
{}
run %windir%\System32\DisplaySwitch.exe /internal
Run, mmsys.cpl 
  WinWait,Sound ; Change "Sound" to the name of the window in your local language 
  ControlSend,SysListView321,{Down 1} ; This number selects the matching audio device in the list, change it accordingly 
  ControlClick,&Set Default ; Change "&Set Default" to the name of the button in your local language 
  ControlClick,OK
  Send, ^!o
Process, Close, Bigbox.exe

Return

 

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

×