Mouse centred when not holding left click and moveable when holding left click down
Mouse centred when not holding left click and moveable when holding left click down
I'm a complete beginner when it comes to AutoHotkey and I'm wondering if there's any way to create a script that centres the mouse to the middle of the screen when you're not holding down left click, but lets you move it when holding it down. I also want this script to only work when I'm using the Firefox browser application.
Re: Mouse centred when not holding left click and moveable when holding left click down
Code: Select all
CoordMode, Mouse, Screen
CenterActive := 1
SetTimer, CenterMouse, 50
return
CenterMouse:
if CenterActive && WinActive("ahk_exe firefox.exe")
MouseMove, A_ScreenWidth/2, A_ScreenHeight/2, 0
return
#IfWinActive, ahk_exe firefox.exe
LButton::
CenterActive := 0
KeyWait, LButton
CenterActive := 1
return
#If
Esc::ExitApp
Re: Mouse centred when not holding left click and moveable when holding left click down
Nice! Btw can you please explain this one line?boiler wrote:Code: Select all
CoordMode, Mouse, Screen CenterActive := 1 SetTimer, CenterMouse, 50 return CenterMouse: if CenterActive && WinActive("ahk_exe firefox.exe") MouseMove, A_ScreenWidth/2, A_ScreenHeight/2, 0 return #IfWinActive, ahk_exe firefox.exe LButton:: CenterActive := 0 KeyWait, LButton CenterActive := 1 return #If Esc::ExitApp
if CenterActive && WinActive("ahk_exe firefox.exe")
I am your average ahk newbie. Just.. a tat more cute.
Re: Mouse centred when not holding left click and moveable when holding left click down
It means that it will only do what follows (the MouseMove) if the value of the variable CenterActive is true (or anything that is not false, like 1) and that FireFox is the active window.
Re: Mouse centred when not holding left click and moveable when holding left click down
so 'if *variable* &'boiler wrote:It means that it will only do what follows (the MouseMove) if the value of the variable CenterActive is true (or anything that is not false, like 1) and that FireFox is the active window.
means if variable is not false?
and the second & is and?
Or does variable &&
mean if variable is not false?
I am your average ahk newbie. Just.. a tat more cute.
Re: Mouse centred when not holding left click and moveable when holding left click down
Thank you so much, it's exactly what I need. However, I can't seem to click or select anything in the browser when using this script, is there any solution to this problem?boiler wrote:Code: Select all
CoordMode, Mouse, Screen CenterActive := 1 SetTimer, CenterMouse, 50 return CenterMouse: if CenterActive && WinActive("ahk_exe firefox.exe") MouseMove, A_ScreenWidth/2, A_ScreenHeight/2, 0 return #IfWinActive, ahk_exe firefox.exe LButton:: CenterActive := 0 KeyWait, LButton CenterActive := 1 return #If Esc::ExitApp
Re: Mouse centred when not holding left click and moveable when holding left click down
if variable evaluates variable itself to see if it's true. A variable value of 0, False, or "" (null string) is false. Anything else is true. I used 1 to represent true, which is standard.Nwb wrote:so 'if *variable* &'
means if variable is not false?
and the second & is and?
Or does variable &&
mean if variable is not false?
&& means "and" so both parts have to be true -- the varible has to be true and the WinActive has to be true.
Re: Mouse centred when not holding left click and moveable when holding left click down
I don't see how you can expect to select or click on anything if you need to hold the mouse button down just to be able to move the mouse, which is what you wanted. Perhaps you didn't think through how this would even be usable.MatthewTheBeginner wrote:Thank you so much, it's exactly what I need. However, I can't seem to click or select anything in the browser when using this script, is there any solution to this problem?
Re: Mouse centred when not holding left click and moveable when holding left click down
As said, I don't think it is possible not without another key intervention. Try this:
f pauses the script. You can select whatever you want as the hotkey instead of f. Click f to stop the mouse from being in the center, allowing you to move it, and click f again so the mouse goes back to the center.
Is that what you wanted?
Code: Select all
CoordMode, Mouse, Screen
CenterActive := 1
SetTimer, CenterMouse, 50
return
CenterMouse:
if CenterActive && WinActive("ahk_exe firefox.exe")
MouseMove, A_ScreenWidth/2, A_ScreenHeight/2, 0
return
#IfWinActive, ahk_exe firefox.exe
LButton::
CenterActive := 0
KeyWait, LButton
CenterActive := 1
return
#If
f:: ; change to preferred hotkey
Pause, Toggle
return
Esc::ExitApp
Is that what you wanted?
I am your average ahk newbie. Just.. a tat more cute.
Re: Mouse centred when not holding left click and moveable when holding left click down
Thank you soooooooooo much! I didn't know if *variable* was that. NOW IT ALL MAKES SENSE HEHE I was trying so hard to understand how toggling and all of that works and now it's all so clear. Can't thank you enough!boiler wrote:if variable evaluates variable itself to see if it's true. A variable value of 0, False, or "" (null string) is false. Anything else is true. I used 1 to represent true, which is standard.Nwb wrote:so 'if *variable* &'
means if variable is not false?
and the second & is and?
Or does variable &&
mean if variable is not false?
&& means "and" so both parts have to be true -- the varible has to be true and the WinActive has to be true.
I am your average ahk newbie. Just.. a tat more cute.
Who is online
Users browsing this forum: No registered users and 123 guests