AutoHotkey Community

It is currently May 27th, 2012, 5:17 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: July 9th, 2009, 8:05 pm 
Offline

Joined: July 12th, 2007, 4:23 pm
Posts: 8
Greetings,

I was wondering if anyone could help me modify the code in this post in two ways:

  1. The cursor should hide after X seconds.
  2. The cursor should come back when the mouse moves.


I looked around this site and others to see if I could find an AHK script that would work, then tried to do it myself, but I wasn't sure how to handle the timer (for disappearing) and the fade back in. Plus, I'm at work right now and probably shouldn't be messing around with this on company time!! :)

Pointers to online documentation is fine, since I did not RTFM. I can probably take over from there and, if not, I can always come back and bother you all again.

Thanks,
-- Dave


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 9th, 2009, 8:27 pm 
Offline

Joined: May 17th, 2007, 6:03 pm
Posts: 391
Location: Titan
I believe if you RTFM ;) at Variables and Expressions for the A_TimeIdlePhysical entry you should get a good idea on how to get 1.

However, it will also need you not to press any keyboard key. :?
Also, supposed that you meant:
"The cursor should hide after X seconds" of being idle.

Maybe someone else can come with a better suggestion that would only take the mouse inactivity into account.



As for 2. I'd suggest to:
- do a loop
- using MouseGetPos to store the coordinates in variables
- and compare these coordinates with coordinates previously stored (when the hiding is initiated).

In other words continuously compare old and new coordinates and unhide the cursor when they become different.
________
JUSTIN BIEBER FAN


Last edited by lilalurl.T32 on February 11th, 2011, 10:13 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 9th, 2009, 8:30 pm 
Offline

Joined: June 8th, 2006, 9:38 pm
Posts: 307
Didn't really look at the thread you linked to, but perhaps this working example will be helpful:

Code:
#NoEnv
#SingleInstance force

OnMessage(0x200, "WM_MOUSEMOVE")

Gui, Show, w300 h300
return

GuiClose:
exitApp

WM_MOUSEMOVE() {
static hidden:=0
; mouse moved and cursor is hidden -> show it
if hidden {
    DllCall("ShowCursor", "Int", 1)
    hidden:=0
    return
  }
; specify negative period to run timer only one:
SetTimer, hideCursor, -2000
return

hideCursor:
DllCall("ShowCursor", "Int", 0)
hidden:=1
return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 3rd, 2011, 7:45 pm 
is there any way to make this work without a gui? it seems to work (for me: Win7 AHK_L) only when the gui is active.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 3rd, 2011, 7:55 pm 
Offline

Joined: June 7th, 2008, 6:00 am
Posts: 389
Code:
Last_Move := A_TickCount
State := True

Loop
{
   MouseGetPos, Mouse_X, Mouse_Y
   If(Mouse_X != Last_X || Mouse_Y != Last_Y)
   {
      If(State == False)
         SystemCursor("On")
      State := True
      Last_Move := A_TickCount
   }
   If(A_TickCount > Last_Move + 3000 && State == True) ;Change the 3000 to the desired time...
   {
      SystemCursor("Off")
      State := False
   }
   Last_X := Mouse_X, Last_Y := Mouse_Y
}



;### This function taken from the tutorial ###

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% )
    }
}


;). Hides the mouse after 3 seconds.

_________________
Image
[Functions] Wicked's Collection Of Functions - Check it out!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 3rd, 2011, 9:17 pm 
Offline

Joined: July 12th, 2007, 4:23 pm
Posts: 8
Excellent. It's amazing what you get notified about on forums when you never remove your subscriptions. The specific need for this script is no longer ... needful ... at the moment, but I've copied it all down and can confirm that it does what I wanted it to do. I'll hang onto it; one never knows when this sort of thing might be useful.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 3rd, 2011, 11:47 pm 
this does indeed work well but i wonder if it could be simplified using:

OnMessage(0x200, "WM_MOUSEMOVE")

unfortunately, from what i can tell from the script above, WM_MOUSEMOVE only applies to a created GUI. is that right?


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], XstatyK, Yahoo [Bot] and 75 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group