Notifications
Clear all

[Closed] mousetracking and capturing keys

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.

1 Reply

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 [b]cbReturn[/b] 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