 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
dashifen
Joined: 12 Jul 2007 Posts: 8
|
Posted: Thu Jul 09, 2009 7:05 pm Post subject: Hide Mouse Cursor When Idle |
|
|
Greetings,
I was wondering if anyone could help me modify the code in this post in two ways:
- The cursor should hide after X seconds.
- 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 |
|
| Back to top |
|
 |
lilalurl.T32
Joined: 17 May 2007 Posts: 391 Location: Titan
|
Posted: Thu Jul 09, 2009 7:27 pm Post subject: |
|
|
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 Fri Feb 11, 2011 9:13 pm; edited 1 time in total |
|
| Back to top |
|
 |
Roland
Joined: 08 Jun 2006 Posts: 307
|
Posted: Thu Jul 09, 2009 7:30 pm Post subject: |
|
|
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
} |
|
|
| Back to top |
|
 |
cracksloth Guest
|
Posted: Mon Jan 03, 2011 6:45 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Wicked
Joined: 07 Jun 2008 Posts: 369
|
Posted: Mon Jan 03, 2011 6:55 pm Post subject: |
|
|
| 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. _________________
[Functions] Wicked's Collection Of Functions - Check it out! |
|
| Back to top |
|
 |
dashifen
Joined: 12 Jul 2007 Posts: 8
|
Posted: Mon Jan 03, 2011 8:17 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
cracksloth Guest
|
Posted: Mon Jan 03, 2011 10:47 pm Post subject: |
|
|
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? |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|