Hide mouse cursor when Skyrim has focus

This feature has now been implemented in AHKGameFrontend V0.2!

Annoyed that the mouse cursor keeps appearing when running the game in windowed mode? Here is a workaround!

How to use

1. Download and install AutoHotkey

2. Copy and paste the script below into an empty text file, save as SkyrimMouseHide.ahk and double click it.

OR

1. Download and install AutoHotkey

2. Download this AHK file and run.

OR

1. Download this compiled executable script and run.
MD5: cadc00d1feea17c6ddadc7adbdcf4bdc

The script

I do not take any credit whatsoever for this, I simply added an IF statement, credit should go to lonewolfdon @ this forum post.

; Script to hide cursor http://forums.steampowered.com/forums/showthread.php?t=1432431
; Minor edits by Nirklars

SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SystemCursor("Init")

SetTimer, CheckIdle, 250
return

CheckIdle:
if WinActive("ahk_class Skyrim") 
{
    SystemCursor("Off")
}
else
{
    SystemCursor("On")
}
return

#Persistent
OnExit, ShowCursor  ; Ensure the cursor is made visible when the script exits.
return

ShowCursor:
SystemCursor("On")
ExitApp

SystemCursor(OnOff=1)   ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
    static AndMask, XorMask, $, h_cursor
        ,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
        , b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13   ; blank cursors
        , h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13   ; handles of default cursors
    if (OnOff = "Init" or OnOff = "I" or $ = "")       ; init when requested or at first call
    {
        $ = h                                          ; active default cursors
        VarSetCapacity( h_cursor,4444, 1 )
        VarSetCapacity( AndMask, 32*4, 0xFF )
        VarSetCapacity( XorMask, 32*4, 0 )
        system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
        StringSplit c, system_cursors, `,
        Loop %c0%
        {
            h_cursor   := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
            h%A_Index% := DllCall( "CopyImage",  "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
            b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
                , "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
        }
    }
    if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
        $ = b  ; use blank cursors
    else
        $ = h  ; use the saved cursors

    Loop %c0%
    {
        h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
        DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
    }
}
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s