Jump to content


Photo

Hide/show Mouse Cursor


  • Please log in to reply
9 replies to this topic

#1 ViperBMX

ViperBMX

    Advanced Member

  • Members
  • PipPipPip
  • 157 posts
  • Gender:Male
  • Location:Huntington Beach, CA

Posted 26 December 2009 - 09:12 PM

I'm looking to hide the mouse cursor after a few seconds of no movement of the mouse, then show the cursor after any movement..basically like a screensaver.
I have this code to hide the mouse if no movement is detected after 3 seconds, but how do I have the mouse show after movement and after the timer has executed?
Just throw this code in an empty scene and it hides the cursor after 3 seconds.

onSelfEvent (load) {
if(!someListener) {
_global.someListener = new Object();
someListener.timeoutCounter=someListener.timeoutSeconds=3;
someListener.onKeyDown=function() {
someListener.timeoutCounter=someListener.timeoutSeconds;
}
someListener.onMouseMove=someListener.onKeyDown;
someListener.onMouseWheel=someListener.onKeyDown;
someListener.onMouseDown=someListener.onKeyDown;
someListener.intvl=setInterval(function()
{
if(Key.isDown(2))someListener.timeoutCounter=someListener.timeoutSeconds;},20);
someListener.intvl=setInterval(function()
{
if(!--someListener.timeoutCounter)Mouse.hide();},1000)
{
}
Mouse.addListener(someListener);
Key.addListener(someListener);
}
}


Thanks for any help.
-Phil

#2 crslz

crslz

    Advanced Member

  • Members
  • PipPipPip
  • 1872 posts
  • Gender:Male
  • Location:Europe, Belgium, West-vl (dutch language)
  • Interests:swishmax, linux, windows, vb.net, photoshop, html, css, php, javascript, jQuery, drupal, wordpress...

Posted 27 December 2009 - 06:05 AM

hi,

Mouse.hide()

Mouse.show()

#3 ViperBMX

ViperBMX

    Advanced Member

  • Members
  • PipPipPip
  • 157 posts
  • Gender:Male
  • Location:Huntington Beach, CA

Posted 27 December 2009 - 06:14 AM

um yea.. that's good and all, but how would that Mouse.show() fit in this script?

Attached Files


-Phil

#4 ViperBMX

ViperBMX

    Advanced Member

  • Members
  • PipPipPip
  • 157 posts
  • Gender:Male
  • Location:Huntington Beach, CA

Posted 27 December 2009 - 07:22 AM

nevermind, got it.. I guess I ask these questions too soon sometimes and at 3am when I am delirious..
here's the fix for anyone interested:
onMouseMove = function() {Mouse.show()}
I kept leaving out the function() and { } when I was trying before.



onSelfEvent (load) {
if(!someListener) {
_global.someListener = new Object();
someListener.timeoutCounter=someListener.timeoutSeconds=3;
someListener.onKeyDown=function() {
someListener.timeoutCounter=someListener.timeoutSeconds;
}
someListener.onMouseMove=someListener.onKeyDown;
someListener.onMouseWheel=someListener.onKeyDown;
someListener.onMouseDown=someListener.onKeyDown;
someListener.intvl=setInterval(function()
{
if(Key.isDown(1))someListener.timeoutCounter=someListener.timeoutSeconds;},20);
someListener.intvl=setInterval(function()
{
if(!--someListener.timeoutCounter)Mouse.hide();},1000)
{
}
onMouseMove = function() {Mouse.show()}
Mouse.addListener(someListener);
Key.addListener(someListener);
}
}

Attached Files


-Phil

#5 DrJohn

DrJohn

    Advanced Member

  • Members
  • PipPipPip
  • 587 posts
  • Gender:Male
  • Location:Stillwater, MN / USA

Posted 27 December 2009 - 03:55 PM

nevermind, got it..


I was in the middle of working on this when you posted your own answer, so now that I've finished, I figured I'd post it anyway, in case anyone finds it edifying ...

My solution:

/* =========================================================================| Set up listeners to hide mouse after 3 seconds inactivity==========================================================================*/function register_hide_mouse(){    Mouse.removeListener(_root.m);    Key.removeListener(_root.m);    _root.m.onMouseMove = m.onMouseDown = m.onMouseUp = m.onKeyDown = m.onKeyUp = function()    {        clearInterval(_root.id);        _root.id = setInterval        (            function()            {                Mouse.hide();                _root.register_show_mouse();  // Once hidden, set up to show again on activity            },            3000        );    }    Mouse.addListener(_root.m);    Key.addListener(_root.m);}/* =========================================================================| Set up to show mouse after activity==========================================================================*/function register_show_mouse(){    Mouse.removeListener(_root.m);    Key.removeListener(_root.m);    _root.m.onMouseMove = m.onMouseDown = m.onMouseUp = m.onKeyDown = m.onKeyUp = function()    {        Mouse.show();        _root.register_hide_mouse();  // Once shown, set up to hide again after 3 seconds    }    Mouse.addListener(_root.m);    Key.addListener(_root.m);}/* ====================================================================== */onSelfEvent(load){    var m : Object = new Object;    register_hide_mouse();}

/John

#6 ViperBMX

ViperBMX

    Advanced Member

  • Members
  • PipPipPip
  • 157 posts
  • Gender:Male
  • Location:Huntington Beach, CA

Posted 27 December 2009 - 05:06 PM

Thanks for working on this..
the only thing I notice is that if you're on mouse down, your code still hides the mouse..was that your intention?
-Phil

#7 DrJohn

DrJohn

    Advanced Member

  • Members
  • PipPipPip
  • 587 posts
  • Gender:Male
  • Location:Stillwater, MN / USA

Posted 28 December 2009 - 07:28 AM

Thanks for working on this..
the only thing I notice is that if you're on mouse down, your code still hides the mouse..was that your intention?


I was never really working on it for any reason other than idle curiosity, so I didn't have any strong intentions. But you are right -- I didn't notice that. It would be better if it didn't hide when the mouse is down.

So I came up with a fix for that problem (attached). But I've noticed it's still not quite right. If you hold the mouse down and, while doing so, generate another event (e.g., mouse move or keystroke), it will hide the mouse after 3 seconds. So there's still work to do.

Yours doesn't seem to suffer from either of the above problems. However, I've noticed with yours that, when the mouse is hidden, it doesn't reappear on mouse down or keystroke, which, if you're really trying to imitate a screen saver, it should probably do.

/John

#8 ViperBMX

ViperBMX

    Advanced Member

  • Members
  • PipPipPip
  • 157 posts
  • Gender:Male
  • Location:Huntington Beach, CA

Posted 28 December 2009 - 07:45 AM

Thanks for pointing that out!..actually I didn't think I needed that, but in a couple of instances I do..I didn't however want it to show on a keystroke.. This is technically a widget that I run as a screensaver to occupy the entire screen.. here's the easy fix on line 20.. onMouseDown = function() {Mouse.show()}

onSelfEvent (load) {
if(!someListener) {
_global.someListener = new Object();
someListener.timeoutCounter=someListener.timeoutSeconds=3;
someListener.onKeyDown=function() {
someListener.timeoutCounter=someListener.timeoutSeconds;
}
someListener.onMouseMove=someListener.onKeyDown;
someListener.onMouseWheel=someListener.onKeyDown;
someListener.onMouseDown=someListener.onKeyDown;
someListener.intvl=setInterval(function()
{
if(Key.isDown(1))someListener.timeoutCounter=someListener.timeoutSeconds;},20);
someListener.intvl=setInterval(function()
{
if(!--someListener.timeoutCounter)Mouse.hide();},1000)
{
}
onMouseMove = function() {Mouse.show()}
onMouseDown = function() {Mouse.show()}
onKeyDown = function() {Mouse.show()}
Mouse.addListener(someListener);
Key.addListener(someListener);
}
}
-Phil

#9 DrJohn

DrJohn

    Advanced Member

  • Members
  • PipPipPip
  • 587 posts
  • Gender:Male
  • Location:Stillwater, MN / USA

Posted 28 December 2009 - 07:50 AM

Thanks for pointing that out!..actually I didn't think I needed that, but in a couple of instances I do..I didn't however want it to show on a keystroke.. This is technically a widget that I run as a screensaver to occupy the entire screen.. here's the easy fix on line 20.. onMouseDown = function() {Mouse.show()}


Attached is my fixed version. It made a bit of a mess of what I thought was otherwise fairly well-structured code. :-)

Anyway, thanks for the interesting problem. Sometimes I just work on them for the heck of it ...

/John

#10 ViperBMX

ViperBMX

    Advanced Member

  • Members
  • PipPipPip
  • 157 posts
  • Gender:Male
  • Location:Huntington Beach, CA

Posted 28 December 2009 - 07:58 AM

Oh yea..I like working on this stuff just for the heck of it too.. would make an awesome job if I could get paid for it.. I'd even work more than 8 hours a day here trying to fix others problems..haha
along with fixing my own problems too!
Thanks for helping out John..
-Phil




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users