Disable mouse input in games
Disable mouse input in games
Hi can someone help me with this problem?
When i want to play certain pc games like cuphead and jump force they reveal my mouse and keyboard as first priority, before the controller
this sometimes cause a problem because if i didnt remember to connect the controller first i have to restart the game
also some other games bind my mouse in their windows and to have freedoom i have to alt tab ( like dragonball xenoverse 2 )
i tried something with BlockInput but the thing is i dont have to block the mouse in all the pc but onl that game
is there a way to do it? maybe hiding the device?
Thanks
When i want to play certain pc games like cuphead and jump force they reveal my mouse and keyboard as first priority, before the controller
this sometimes cause a problem because if i didnt remember to connect the controller first i have to restart the game
also some other games bind my mouse in their windows and to have freedoom i have to alt tab ( like dragonball xenoverse 2 )
i tried something with BlockInput but the thing is i dont have to block the mouse in all the pc but onl that game
is there a way to do it? maybe hiding the device?
Thanks
Re: Disable mouse input in games
Code: Select all
Loop {
WinWaitActive, ahk_exe notepad.exe
BlockInput, MouseMove
WinWaitNotActive
BlockInput, MouseMoveOff
}
Re: Disable mouse input in games
Yeah i already tried that way, but i was trying to disable mouse moving and input only inside the specific application, with that type of code when the window gets focus it disables the mouse moving for the whole OS until the windows loses focus. What i meant to do is to have the window ignore mouse moving/input as if there was no native support in it.mikeyww wrote: ↑04 Jun 2021, 17:36Code: Select all
Loop { WinWaitActive, ahk_exe notepad.exe BlockInput, MouseMove WinWaitNotActive BlockInput, MouseMoveOff }
Re: Disable mouse input in games
There is ClipCursor. Another approach is to use SetTimer with MouseGetPos to see what window is under the cursor, and act accordingly.
Alternatives:
Alternatives:
Code: Select all
#Persistent
SetTimer, Check, 100
Check:
MouseGetPos,,, uid
WinGet, proc, ProcessName, % wTitle := "ahk_id " uid
If (proc != "notepad.exe")
Return
WinGetPos, x, y,,, %wTitle%
CoordMode, Mouse
MouseMove, x - 5, y - 5
Return
Code: Select all
#Persistent
Loop {
WinWaitActive, % "ahk_exe " proc := "notepad.exe"
SetTimer, Check, 100
WinWaitNotActive
BlockInput, MouseMoveOff
}
Check:
MouseGetPos,,, uid
WinGet, thisProc, ProcessName, ahk_id %uid%
If (thisProc != proc)
Return
BlockInput, MouseMove
SetTimer,, Off
Return
Re: Disable mouse input in games
i tried all of them but still my mouse is blocked somehowmikeyww wrote: ↑05 Jun 2021, 09:29There is ClipCursor. Another approach is to use SetTimer with MouseGetPos to see what window is under the cursor, and act accordingly.
Alternatives:
Code: Select all
#Persistent SetTimer, Check, 100 Check: MouseGetPos,,, uid WinGet, proc, ProcessName, % wTitle := "ahk_id " uid If (proc != "notepad.exe") Return WinGetPos, x, y,,, %wTitle% CoordMode, Mouse MouseMove, x - 5, y - 5 Return
Code: Select all
#Persistent Loop { WinWaitActive, % "ahk_exe " proc := "notepad.exe" SetTimer, Check, 100 WinWaitNotActive BlockInput, MouseMoveOff } Check: MouseGetPos,,, uid WinGet, thisProc, ProcessName, ahk_id %uid% If (thisProc != proc) Return BlockInput, MouseMove SetTimer,, Off Return
the only way would be rewrite the game code i guess or modding
thanks
Re: Disable mouse input in games
In a sense, these are simulations. One will prevent the mouse from moving over the window. The other will block mouse input when the window becomes active and the mouse is over the window. As far as I can tell, this fits the description, "have the window ignore mouse moving/input". If you instead just want the mouse buttons not to work, they can be set to Return when the target window is active.
Re: Disable mouse input in games
i only want to make the game ignore mouse and keyboard while also keeping the game window active but only for that game not all the pcmikeyww wrote: ↑10 Jun 2021, 16:01In a sense, these are simulations. One will prevent the mouse from moving over the window. The other will block mouse input when the window becomes active and the mouse is over the window. As far as I can tell, this fits the description, "have the window ignore mouse moving/input". If you instead just want the mouse buttons not to work, they can be set to Return when the target window is active.
Re: Disable mouse input in games
I am finding a lack of clarity here. Your reports:
1. "i dont have to block the mouse in all the pc but onl that game"; followed by:
2. "but still my mouse is blocked somehow"; followed by:
3. "make the game ignore mouse and keyboard while also keeping the game window active but only for that game not all the pc"
At this point, perhaps you can describe exactly what should happen to the mouse, and exactly what event should trigger that.
To try yourself: the scripts here show how you can detect when your target window is active (WinWaitActive), and then act following that. See BlockInput for an explanation of how the block works. The scripts here also show how to determine which window is under the mouse (MouseGetPos), so you can adjust that if needed. Note that some uses of BlockInput may require admin mode. Links are provided in this paragraph.
In case helpful, here is a way to block mouse buttons.
Here is an interesting script to block the keyboard. You could probably integrate this into your script.
That's about all I know with these various techniques. You have a bunch of examples here. You can pick the ones that you want and use them in your script. It seems to me that an easy one is the first one that simply prevents the mouse from hovering anywhere over your target window. I think that would meet your description for the script. If you want to block all keyboard input, then you can simply make the window inactive as soon as it becomes active.
1. "i dont have to block the mouse in all the pc but onl that game"; followed by:
2. "but still my mouse is blocked somehow"; followed by:
3. "make the game ignore mouse and keyboard while also keeping the game window active but only for that game not all the pc"
At this point, perhaps you can describe exactly what should happen to the mouse, and exactly what event should trigger that.
To try yourself: the scripts here show how you can detect when your target window is active (WinWaitActive), and then act following that. See BlockInput for an explanation of how the block works. The scripts here also show how to determine which window is under the mouse (MouseGetPos), so you can adjust that if needed. Note that some uses of BlockInput may require admin mode. Links are provided in this paragraph.
In case helpful, here is a way to block mouse buttons.
Code: Select all
#If mouseOver("notepad")
LButton::
RButton::
MButton::
XButton1::
XButton2::SoundBeep, 1000
#If
mouseOver(proc) {
MouseGetPos,,, uid
WinGet, thisProc, ProcessName, ahk_id %uid%
Return thisProc = proc ".exe"
}
That's about all I know with these various techniques. You have a bunch of examples here. You can pick the ones that you want and use them in your script. It seems to me that an easy one is the first one that simply prevents the mouse from hovering anywhere over your target window. I think that would meet your description for the script. If you want to block all keyboard input, then you can simply make the window inactive as soon as it becomes active.
Re: Disable mouse input in games
mikeyww wrote: ↑13 Jun 2021, 18:19Code: Select all
#If mouseOver("notepad") LButton:: RButton:: MButton:: XButton1:: XButton2::SoundBeep, 1000 #If mouseOver(proc) { MouseGetPos,,, uid WinGet, thisProc, ProcessName, ahk_id %uid% Return thisProc = proc ".exe" }
THIS is actually what i need and seems too works but only for a few games (game title can be tricky i guess)
like it works with cuphead
Code: Select all
#If mouseOver("Cuphead")
LButton::
RButton::
MButton::
XButton1::
XButton2::SoundBeep, 100
#If
mouseOver(proc) {
MouseGetPos,,, uid
WinGet, thisProc, ProcessName, ahk_id %uid%
Return thisProc = proc ".exe"
}
well doesnt prevent games from "capturing" the mouse like again db xenoverse 2 but its a start
then what if i wanna also add the keyboard block?
BlockInput seems too much as i cant use keyboard for other things
i tried
#If keyboardOver("Cuphead")
EscButton::
give an error on every button or even "key", what should i use?
Re: Disable mouse input in games
OK. This particular script handles specified process names. You could change the function if you need window titles instead.
Perhaps you just want to disable the window, easy to do.
The name of Esc is Esc. See: list of keys.
Perhaps you just want to disable the window, easy to do.
Code: Select all
WinSet, Disable,, ahk_exe notepad.exe
Re: Disable mouse input in games
ooh thats whymikeyww wrote: ↑16 Jun 2021, 16:28OK. This particular script handles specified process names. You could change the function if you need window titles instead.
Perhaps you just want to disable the window, easy to do.
The name of Esc is Esc. See: list of keys.Code: Select all
WinSet, Disable,, ahk_exe notepad.exe
disable the window no because i need to at least play with controller, i only have to disable mouse and keyboard not all
ok the esc now works and all the others too!
thanks for the patience gonna try many games
Re: Disable mouse input in games
OK. You can always try the "Block the keyboard" linked code. I have not tested it (and it might really block your keyboard, too!). You could try it-- when your target window is active-- but leave one key enabled so that you can re-enable your keyboard when needed. Example is below.
Code: Select all
Loop {
WinWaitActive, % wTitle := "ahk_exe notepad.exe"
SoundBeep, 1500
blockKB("On")
WinWaitNotActive
SoundBeep, 1500
blockKB("Off")
SoundBeep, 1000
}
F3::WinMinimize, %wTitle%
blockKB(state) {
; https://stackoverflow.com/questions/61690600/how-to-make-blockinput-on-off-only-block-keyboard-inputs-not-mouse
Loop, 512
Hotkey, % Format("*SC{:X}", A_Index), KeyboardKey, %state% UseErrorLevel
Hotkey, *SC3D, Off ; F3
KeyboardKey:
Return
}
Re: Disable mouse input in games
well its similar but more problematic, cant even alt tabmikeyww wrote: ↑16 Jun 2021, 17:29OK. You can always try the "Block the keyboard" linked code. I have not tested it (and it might really block your keyboard, too!). You could try it-- when your target window is active-- but leave one key enabled so that you can re-enable your keyboard when needed. Example is below.
Code: Select all
Loop { WinWaitActive, % wTitle := "ahk_exe notepad.exe" SoundBeep, 1500 blockKB("On") WinWaitNotActive SoundBeep, 1500 blockKB("Off") SoundBeep, 1000 } F3::WinMinimize, %wTitle% blockKB(state) { ; https://stackoverflow.com/questions/61690600/how-to-make-blockinput-on-off-only-block-keyboard-inputs-not-mouse Loop, 512 Hotkey, % Format("*SC{:X}", A_Index), KeyboardKey, %state% UseErrorLevel Hotkey, *SC3D, Off ; F3 KeyboardKey: Return }
the only way would be CTRL ALT CANC
good thing i have the mouse free ahah
Re: Disable mouse input in games
Well, you did say block the keyboard.....
But F3 was left alone to minimize the target window.
But F3 was left alone to minimize the target window.