PDA

View Full Version : mousetracking and capturing keys


VVaari
06-10-2009, 12:32 PM
Is it possible to abort mouseTracking with other way than rightclick or ESC? Like when user presses button in rollout, tracking is aborted. I tried sending abort message to trackers callback function but it didn't work.

And can i capture key presses? For example if i need to know when user aborts mousetracking using ESC.

magicm
06-10-2009, 01:51 PM
Afaik, you can't abort a mouseTrack programmatically. What you could do is use a flag and check the state of that flag in the callback function, eg:
(
local abortMouseTrack = false

fn myCallback msg r obj f shift ctrl alt =
(
local cbReturn = #continue

if abortMouseTrack then
cbReturn = #abort
else
(
-- add code here, and change cbReturn value if needed.
)

cbReturn
)

mouseTrack trackCallback:myCallback
)
Then, you simply set the flag to true, for example when a button is pressed:
on btnCancel pressed do abortMouseTrack = true
The variable abortMouseTrack should obviously be created in the same scope as the callback function AND the button press handler, so both function can access it. You could also make it a global variable, but it's better to use locals when possible.

Note: the mouseTrack won't stop immediately, but when the user moves the mouse over the viewport (which triggers the mouseTrack callback).

[Edit] the mouseTrack function returns the value that was returned by the callback function. So in the above example, if you set the cbReturn variable to anything other than #continue, that's the value mouseTrack will return.

Martijn

CGTalk Moderation
06-10-2009, 01:51 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.