Help with hiding my cursor only when a certain webpage is open and in focus Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LegzRwheelz
Posts: 56
Joined: 04 Nov 2019, 17:46

Help with hiding my cursor only when a certain webpage is open and in focus

Post by LegzRwheelz » 22 Mar 2023, 21:54

Hey guys, I am back for more help. 😬
So if you look in my post history, I have a script that I run from launch that handles a multitude of hotkeys for my HTPC. I use chrome to watch youtube videos in the smart tv format using a user-agent string to spoof my pc being a PS5 and that works great. I use a library I found here viewtopic.php?t=82431 that allows me to load specific cursor schemes as well as a library a that user over at the Launchbox forums created for hiding/restoring the desktop. It works pretty good except if I use winwaitclose within the hotkey for YT, it hangs, never restoring my desktop and as a result I created a winwaitactive loop that waits for that tab to close and it restores the desktop and cursor scheme and now my hotkey works as expected. After figuring this out, I got the idea of extending the loop so it toggles the cursor when the tab is open and when I alt+tab out or press the windows key, it restores the desktop and original cursor scheme. I cannot seem to get this to work though. I have pasted my (currently) working hotkey below:

Code: Select all

#SingleInstance Force
#Persistent
#NoEnv 
#Include, lib\Cursors.ahk
#Include, lib\DeskToggle.ahk
SendMode Input 
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode, 2

insert:: ; Gives back mouse cursor, turns off SMS and kills nav sounds, while still allowing Chrome YTV to cont. running
keywait, insert
	SoftClear()
return

^!v::
keywait, v
	YouTubeTV()
return	


;==========================================================================================================================================================
; Remapped for YouTube TV ONLY
;==========================================================================================================================================================

#IfWinActive, YouTube on TV - Google Chrome

~up::
SoundPlay, %A_ScriptDir%\lib\Data\Assets\Audio\keypress\Move.wav, wait
Return

~down::
SoundPlay, %A_ScriptDir%\lib\Data\Assets\Audio\keypress\Move.wav, wait
Return

~left::
SoundPlay, %A_ScriptDir%\lib\Data\Assets\Audio\keypress\Move.wav, wait
Return

~right::
SoundPlay, %A_ScriptDir%\lib\Data\Assets\Audio\keypress\Move.wav, wait
Return

~Enter::
SoundPlay, %A_ScriptDir%\lib\Data\Assets\Audio\keypress\select.wav, wait
Return

~esc::
SoundPlay, %A_ScriptDir%\lib\Data\Assets\Audio\keypress\escape.wav, wait
Return

~backspace::
SoundPlay, %A_ScriptDir%\lib\Data\Assets\Audio\keypress\backspace.wav, wait
Return

~Media_Play_Pause::
SoundPlay, %A_ScriptDir%\lib\Data\Assets\Audio\keypress\pause.wav, wait
Return

~Media_Stop::
SoundPlay, %A_ScriptDir%\lib\Data\Assets\Audio\keypress\pause.wav, wait
Return

~Media_next::
SoundPlay, "%A_ScriptDir%\lib\Data\Assets\Audio\keypress\nav fwd.wav", wait
Return

~Media_Prev::
SoundPlay, "%A_ScriptDir%\lib\Data\Assets\Audio\keypress\nav prev.wav", wait
Return

+x::Media_Stop
SoundPlay, %A_ScriptDir%\lib\Data\Assets\Audio\keypress\pause.wav, wait
Return

CharacterCycle(list){ ; cycles through characters
	Static i
   If (A_ThisHotKey = A_PriorHotKey and A_TimeSincePriorHotkey < 850) ; if you press the same key within 1 sec, cycle through characters
   {
      Send {BS}      ; erases the last character put in
      i++            ; selects the next character
   }
   Else i = 1        ; if you press a new key, select the first character
   If (i > StrLen(list))
      i = 1          ; wrap around at the end of list
   StringMid c, list, i, 1
   Send %c%          ; sends the selected character
}

VideoSplash(file){
	fs = --fullscreen ; self explanatory
	ng = --intf dummy ;vlc no gui
	pe = --play-and-exit
	vc = --config=lib\Data\PortableApps\VLC\Data\settings\vlcrc ;vlc config file
	VLC = lib\Data\PortableApps\VLC\VLCPortable.exe
	spDir = lib\Data\Assets\Splash\Video ;Splash Videos
    Run, %VLC% %spDir%\%file%.mp4 %fs% %vc% %ng% %pe% ;Run, % VLC " " spDir "\" file ".mp4  " fs " " ng " " pe
}

YouTubeTV(){
    HideDesktop()	
    if WinExist("YouTube on TV - Google Chrome") ;Checks to see if the "YTTV" tab is open in Chrome in order to know how to proceed
        {
            WinActivate ;What "if WinExist" checked for in the previous instruction
            MouseDisable()
            Run, Z:\HTPC\Scripts\lib\Data\Tools\Gamepad_Tools\Controller_Companion\ControllerCompanion.exe
            return
        }
        else  
        {
            VideoSplash("YTTV") ; Video Intro for YTTV
            MouseDisable()
            Run, Z:\HTPC\Scripts\lib\Data\PortableApps\GoogleChromePortable64\App\Chrome-bin\chrome.exe --kiosk https://www.youtube.com/tv#/ --user-data-dir=Z:\HTPC\Scripts\lib\Data\PortableApps\GoogleChromePortable64\Data\profile --profile-directory=Default --user-agent="Mozilla/5.0 (PlayStation; PlayStation 5/2.26) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15" ; Opens YTTV in Chrome in Kiosk mode (not window or tab)
            Run, Z:\HTPC\Scripts\lib\Data\Tools\Gamepad_Tools\Controller_Companion\ControllerCompanion.exe
        Return
        }
    }
    
    loop {
        WinWaitActive, YouTube on TV - Google Chrome
        WinWaitClose
        SoftClear()
    }
    
    SoftClear(){
        KillCC() ;see above
        KillVLC() ;see above
        MouseEnable()
        RestoreDesktop(ToggleEverything[1], ToggleEverything[2])
    }

    KillCC(){
	if !A_IsAdmin
	Run, % "*RunAs " (A_IsCompiled ? "" : A_AhkPath " ") Chr(34) A_ScriptFullPath Chr(34)
	RunWait, TASKKILL /F /IM ControllerCompanion.exe /T,, Hide
}

    KillVLC(){
	if !A_IsAdmin
	Run, % "*RunAs " (A_IsCompiled ? "" : A_AhkPath " ") Chr(34) A_ScriptFullPath Chr(34)
	RunWait, TASKKILL /F /IM VLC.exe /T,, Hide
}

MouseEnable(){
	SetCursorScheme("Volantes Dark")
    BlockInput MouseMoveOff
}

MouseDisable(){
     SetCursorScheme("YTTV") ; makes mouse cursor invisible, must install cursor scheme found in the lib\data\assets\cursors and icons folder
     MouseMove, 0, 2159 ;move the mouse cursor out of the way
     BlockInput MouseMove ;self-explanatory
}
I am sure there is redundant code as well as code that is out of place, but I am nothing more than a novice hobbyist. If anybody can help me with cleaning this up and making this so my cursor visibility as well as hiding/restoring the desktop (the functions are named very simplistically so you should know what it is) and function toggles when my youtube tab is open, I would really appreciate it. If the desktop toggle library is needed, I will update this post.


[Mod action: Moved topic to v1 section. The main section is for v2.]

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Help with hiding my cursor only when a certain webpage is open and in focus  Topic is solved

Post by mikeyww » 22 Mar 2023, 22:03

Hello,

You are posting in the v2 forum.

Code: Select all

#Requires AutoHotkey v1.1.33
#SingleInstance
winTitle := "Help with hiding my cursor only when a certain webpage is open and in focus"
Loop {
 WinWaitActive % winTitle
 SoundBeep 1500
 WinWaitNotActive % winTitle
 SoundBeep 1000
}
Notice that the WinTitle is specified twice. Why? Without the WinTitle the second time, the last found window is used. This window is the same for all tabs in the browser.

LegzRwheelz
Posts: 56
Joined: 04 Nov 2019, 17:46

Re: Help with hiding my cursor only when a certain webpage is open and in focus

Post by LegzRwheelz » 23 Mar 2023, 12:03

mikeyww wrote:
22 Mar 2023, 22:03
Hello,

You are posting in the v2 forum.

Code: Select all

#Requires AutoHotkey v1.1.33
#SingleInstance
winTitle := "Help with hiding my cursor only when a certain webpage is open and in focus"
Loop {
 WinWaitActive % winTitle
 SoundBeep 1500
 WinWaitNotActive % winTitle
 SoundBeep 1000
}
Notice that the WinTitle is specified twice. Why? Without the WinTitle the second time, the last found window is used. This window is the same for all tabs in the browser.
OOF, I apologize for my oversight with where I am posting. I am also extremely grateful of your help. You never fail to amaze me with your knowledge. I am not at home to be able to test this currently, when I am I will test and get back. I have 100% faith in your code though. You have helped me numerous times and never failed me. Some thing I would like clarification on is

Code: Select all

winTitle := "Help with hiding my cursor only when a certain webpage is open and in focus"
I fill this in with the tab name that I am working with, correct?

LegzRwheelz
Posts: 56
Joined: 04 Nov 2019, 17:46

Re: Help with hiding my cursor only when a certain webpage is open and in focus

Post by LegzRwheelz » 23 Mar 2023, 12:04

mikeyww wrote:
22 Mar 2023, 22:03
Hello,

You are posting in the v2 forum.

Code: Select all

#Requires AutoHotkey v1.1.33
#SingleInstance
winTitle := "Help with hiding my cursor only when a certain webpage is open and in focus"
Loop {
 WinWaitActive % winTitle
 SoundBeep 1500
 WinWaitNotActive % winTitle
 SoundBeep 1000
}
Notice that the WinTitle is specified twice. Why? Without the WinTitle the second time, the last found window is used. This window is the same for all tabs in the browser.
OOF, I apologize for my oversight with where I am posting. I am also extremely grateful of your help. You never fail to amaze me with your knowledge. I am not at home to be able to test this currently, when I am I will test and get back. I have 100% faith in your code though. You have helped me numerous times and never failed me. Some thing I would like clarification on is

Code: Select all

winTitle := "Help with hiding my cursor only when a certain webpage is open and in focus"
I fill this in with the tab name that I am working with, correct?

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Help with hiding my cursor only when a certain webpage is open and in focus

Post by mikeyww » 23 Mar 2023, 13:02

Yep! The window title as shown in Window Spy, or it can be just a leading part of that text.

LegzRwheelz
Posts: 56
Joined: 04 Nov 2019, 17:46

Re: Help with hiding my cursor only when a certain webpage is open and in focus

Post by LegzRwheelz » 23 Mar 2023, 19:26

mikeyww wrote:
23 Mar 2023, 13:02
Yep! The window title as shown in Window Spy, or it can be just a leading part of that text.
I want to say that your code worked perfectly and I added a bit of extra-ness to this and not my hotkey finally performs as expected. I am wondering one last thing: So I put this at the very bottom of my script, how would I merge it with my YouTubeTV() function so it is AIO?

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Help with hiding my cursor only when a certain webpage is open and in focus

Post by mikeyww » 23 Mar 2023, 20:04

You don't, and it won't execute if it follows a Return command. Instead, put this code before your first hotkey. Replace each beep with code that you want to execute, or with a function call or Gosub, indicating what should happen when your tab is active, and then what should happen when it is not active.

Post Reply

Return to “Ask for Help (v1)”