WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Mouse event: how to detect no mouse move event, how to set mouse position? (https://forum.worldviz.com/showthread.php?t=3695)

Zhi 04-07-2011 04:12 PM

Mouse event: how to detect no mouse move event, how to set mouse position?
 
Hi,

I am writing a program, which detects the mouse movement event and does certain stuff. However, when the mouse stops moving, I need to reset a variable. Is there an event that I can use to do this?

If there is no way to detect the non-movement event, a way around is to check the mouse position change periodically. However, when the mouse moves to the edge of the window or screen, its position value will be fixed. Is there any way to reset the mouse position? I see the viz.mouse.getposition(). Is there something like viz.mouse.setposition() that I can use?

Thanks,
Zhi

farshizzo 04-11-2011 05:41 PM

You can use a delayed timer to detect when the mouse stops moving after a certain amount of time. The following script shows how to do this:
Code:

import viz
viz.go()

MOUSE_STILL_EVENT = viz.getEventID('MouseStillEvent')

class MouseStillHandler(viz.EventClass):
        def __init__(self,delay=0.25):
                viz.EventClass.__init__(self)
                self.still_delay = delay

                self.callback(viz.TIMER_EVENT,self._onTimer)
                self.callback(viz.MOUSE_MOVE_EVENT,self._onMouseMove)

        def _onTimer(self,num):
                viz.sendEvent(MOUSE_STILL_EVENT,viz.Event(delay=self.still_delay))
                self.killtimer(0)

        def _onMouseMove(self,e):
                self.killtimer(0)
                self.starttimer(0,self.still_delay)


handler = MouseStillHandler()

def onMouseStill(e):
        print 'Mouse still'

viz.callback(MOUSE_STILL_EVENT,onMouseStill)


Zhi 04-11-2011 06:16 PM

Thank you farshizzo, the script works well, though I do not really understand the codes.

Is that the MOUSE_STILL_EVENT is a variable you create, while the 'MouseStillEvent' is a constant defined somewhere else?

Sorry for the newbie question.

farshizzo 04-11-2011 06:25 PM

The viz.getEventID function is used to generate a custom event ID given a unique event name.


All times are GMT -7. The time now is 12:43 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC