Auto-hide mouse cursor during gameplay Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Auto-hide mouse cursor during gameplay

Post by Evil-e » 30 Jan 2020, 13:56

Need For Speed: World needs the cursor at times, but would like it to vanish when mouse ball is no longer in use... say a second or so. When the mouse ball moves, I would like the cursor to re-appear to use again. I found the following script, but unable to adapt it for my needs:

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=69555&p=299768&hilit=hide+cursor#p299768

The following is one variation that seemed to make sense, but didn't work:

Code: Select all

SystemCursor(OnOff=1) 
{
	if (OnOff == 1)
	{
	   BlockInput MouseMoveOff
	   DllCall("ShowCursor", Int,1)	
	} 
	else 
	{
	   MouseGetPos, , , hwnd
	   Gui Cursor:+Owner%hwnd%
	   BlockInput MouseMove
	   DllCall("ShowCursor", Int,0)	
	}
}
:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Auto-hide mouse cursor during gameplay  Topic is solved

Post by Evil-e » 30 Jan 2020, 20:38

UPDATE: Located a great little application file to hide the cursor. I found two versions, for your mouse hiding pleasure: Both are EXTREMELY light-weight and are applications, so not installed on your machine.

#1: https://download.cnet.com/AutoHideMouseCursor/3001-2084_4-75676781.html (100% stand alone with .ini file for settings) (32bit)

#2: https://www.softwareok.com/?seite=Microsoft/AutoHideMouseCursor (few more options and requires two registry keys for settings) (32/64bit)

This application is designed to be run with launch of Windows, so requires Process, Close, to shut it down when done. I opted for option #1, because I prefer to have it that much more light-weight and the additional features of option #2 are not beneficial for my needs.

I would still like an answer to my OP, if there is an AHK script to hide cursor, but this is a great option :)

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

Tcharr
Posts: 41
Joined: 25 Jan 2020, 15:38

Re: Auto-hide mouse cursor during gameplay

Post by Tcharr » 01 Feb 2020, 07:55


Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Auto-hide mouse cursor during gameplay

Post by Evil-e » 01 Feb 2020, 08:53

@Tcharr ya silly wabbit. That was the same link as in my OP :)

Thanks, but was unable make it work. I tried some variations of it, but no luck :(

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

Tcharr
Posts: 41
Joined: 25 Jan 2020, 15:38

Re: Auto-hide mouse cursor during gameplay

Post by Tcharr » 01 Feb 2020, 11:05

Evil-e wrote:
01 Feb 2020, 08:53
@Tcharr ya silly wabbit. That was the same link as in my OP :)

Thanks, but was unable make it work. I tried some variations of it, but no luck :(

:morebeard:
Oops! I missed the link id.

Maybe this one will help you -> https://www.autohotkey.com/boards/viewtopic.php?p=36693#p36693

Tcharr
Posts: 41
Joined: 25 Jan 2020, 15:38

Re: Auto-hide mouse cursor during gameplay

Post by Tcharr » 01 Feb 2020, 11:07

@Evil-e
Sorry. I missed the post id.
Maybe this one? https://www.autohotkey.com/boards/viewtopic.php?p=36693#p36693

Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Auto-hide mouse cursor during gameplay

Post by Evil-e » 01 Feb 2020, 14:18

@Tcharr Thanks, Bugs ;)

Looks like it would work, but appears to need some "input" to hide / show cursor. What I was looking for is the cursor to auto-hide when not in use for a moment. I have been tinkering with the AutoHideMouseCursor application (linked above) and I have decided that it is the way to go for me. The program launches hidden and the cursor timer starts right away. It has adjustable timer for auto-hide to enable and avoids any interaction with AHK. I have it set for 1 second and is perfect. The moment I move the mouse ball, the cursor shows up where it was left previously.

I appreciate your help, but I now consider this matter closed :beer:

Peace from :morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

Tcharr
Posts: 41
Joined: 25 Jan 2020, 15:38

Re: Auto-hide mouse cursor during gameplay

Post by Tcharr » 01 Feb 2020, 14:53

@Evil-e

Input can be changed to a loop that checks for mouse movement. A_TimeIdle or one of its relatives would be useful, I think. :)

Anyway, I am glad you found a worthy solution to meet your needs. Fare well.

Evil-e
Posts: 262
Joined: 04 Sep 2018, 11:09

Re: Auto-hide mouse cursor during gameplay

Post by Evil-e » 02 Feb 2020, 04:45

@Tcharr

Oooooh, thanks. Will check it out again :)

:morebeard:
I have a bit of experience opening and sending commands to game console and CMD.exe... just ask :)

Duker
Posts: 1
Joined: 08 May 2024, 05:09

Re: Auto-hide mouse cursor during gameplay

Post by Duker » 08 May 2024, 05:39

Sorry for the necro, but this thread favors well in the searches I've done and is very precisely what I was searching for except without a working solution to actually doing it in AHK, so this is what I cobbled together:

Code: Select all

#SingleInstance Force
InstallMouseHook
CoordMode("mouse", "screen")

OnExit (*) => SystemCursor("Show")  ; Ensure the cursor is made visible when the script exits.

winTitle := "ahk_exe NieR Replicant ver.1.22474487139.exe"
waitTime := 750 ; milliseconds

SetTimer(Main, 10)

Main() {

   if WinActive(winTitle) {
      if (A_TimeIdlePhysical > waitTime)
         SystemCursor("Hide")
      else
         SystemCursor("Show")

   } else
      SystemCursor("Show")
}


SystemCursor(cmd) {  ; cmd = "Show|Hide|Toggle|Reload"

   static visible := true, c := Map()
   static sys_cursors := [32512, 32513, 32514, 32515, 32516, 32642, 32643, 32644, 32645, 32646, 32648, 32649, 32650]

   if (cmd = "Reload" or !c.Count) { ; Reload when requested or at first call.
      for i, id in sys_cursors {
         h_cursor := DllCall("LoadCursor", "Ptr", 0, "Ptr", id)
         h_default := DllCall("CopyImage", "Ptr", h_cursor, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0)
         h_blank := DllCall("CreateCursor", "Ptr", 0, "Int", 0, "Int", 0, "Int", 32, "Int", 32, "Ptr", Buffer(32 * 4, 0xFF), "Ptr", Buffer(32 * 4, 0))
         c[id] := { default: h_default, blank: h_blank }
      }
   }

   switch cmd {
      case "Show": visible := true
      case "Hide": visible := false
      case "Toggle": visible := !visible
      default: return
   }

   for id, handles in c {
      h_cursor := DllCall("CopyImage", "Ptr", visible ? handles.default : handles.blank, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0)
      DllCall("SetSystemCursor", "Ptr", h_cursor, "UInt", id)
   }
}

It very simply checks if the game (in my case Nier Replicant) is the active window and hides the cursor after 750 milliseconds of mouse idle time, otherwise the cursor is shown
The SystemCursor function is copied from the DllCall docs: https://www.autohotkey.com/docs/v2/lib/DllCall.htm#ExHideCursor

Post Reply

Return to “Gaming Help (v1)”