Mouse events when dragging a cursor

Hi,

In Igor 6 I wrote a hook function that would run after dragging a cursor to a certain position, by detecting hook events 3 and 5.
I can´t replicate this in Igor 7. If I just click in any part of the window event hooks 3 and 5 are detected by my hook function, but if I drag a cursor, which involves clicking and releasing the left button, only events 4 and 7 are detected.

Any idea how to obtain the same behavior as in Igor 6?

Thanks in advance, Claudio.
execute displayhelptopic "Cursors - Moving Cursor Calls Function"
What is the problem with using Event 7 "cursormoved"? Is there some information that you are missing in that case? That event is also available in Igor 6, so that would make your function work with 6, 7 and 8.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
What is the problem with using Event 7 "cursormoved"? Is there some information that you are missing in that case? That event is also available in Igor 6, so that would make your function work with 6, 7 and 8.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com


Hi john,

I want the hook function to run only when I release the cursor to a new position, not every time the cursor is moved. Therefore events 3 and 5 were more useful to me.

Claudio.
tony wrote:
execute displayhelptopic "Cursors - Moving Cursor Calls Function"


Sorry, would you care to elaborate on this? I have read this section before but I don´t see how it helps my particular problem.

Thanks, Claudio.
Maybe the disappearance of the mouseup event following a cursor move was an unintentional change in Igor 7?

If the cursor is on a trace, the hook function receives event 7 at the end of a move. I'm guessing that 1. you're using free cursors and 2. you want to trigger some function only at the end of a cursor move.

Off the top of my head, one very kludgey way to do this would be to save events in a global variable and check for the event following a cursor moved event. It's embarrassingly ugly, but it seems to work. It relies on the hook not receiving any event other than 7 while the cursor is in motion, and the user not having too steady a hand... (really it's waiting for a mouse moved event following a cursor moved event, and you can code it that way too).

Function MyWindowHook(s)
    STRUCT WMWinHookStruct &s
   
    NVAR V_hook=v_hook
    if(v_hook==7 && s.eventCode!=7)
        print "Cursor moved"
    endif  
    V_hook=s.eventCode 
    return 0
End
Claudioez wrote:
I want the hook function to run only when I release the cursor to a new position, not every time the cursor is moved. Therefore events 3 and 5 were more useful to me.

Hmm... I wrote a very simple window hook function:
Function MyWindowHook(s)
    STRUCT WMWinHookStruct &s

    Variable hookResult = 0

    switch(s.eventCode)
        case 7:             // cursormoved
            print "cursor moved:"
            print "Point number:", s.pointNumber
            if (s.isFree)
                print "Y location:", s.yPointNumber
            endif
            break
    endswitch

    return hookResult       // 0 if nothing done, else 1
End

I installed this on a graph window and put a cursor on the trace. When I click on the cursor and drag it to a new point, it only prints when I release the cursor.

Oh, wait- if I make it a free cursor, then it does, indeed, get activated as I move the cursor around on the graph. Does this describe what you are seeing?

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
OK, yep, a free cursor and a cursor on an image both report a cascade of cursorMoved events while you're still dragging.

Perhaps you can imagine that the event handling inside Igor 7 is vastly different from Igor 6, and that mouse up event got lost in the shuffle. It's quite possible that in Igor 6 it was kind of accidental that the event was reported, but it is useful. Curious that no one has asked for the mouse-down event prior to the cursorMoved events...

In any case, after the nightly build you can get the mouse-up event in both Igor 7 and 8. Thanks for asking about it!

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com

In reply to by johnweeks

Hi,

 

in IP9 with a free cursor on an image I am also seeing continuous triggers of the hook function.

 

Is there a preferred solution?  Again as with the original poster, I would like the hook to fire only after the cursor movement is complete. Cursor moved + mouse up.

 

Andy

If you don't mind the hook function triggering, but want to execute a function if both the cursor was moved and a mouse-up event happened, then you could do the following:

case 7: write into panel's/graph's user data that a cursor move event happened, e.g.:

case 7:
    SetWindow $s.winName userdata(curmoved)="1"
break

case 5: check the user data, and if you get a "1" then execute your function etc. Reset user data afterwards, e.g.:

case 5:
    String check = GetUserData(s.winName,0,"curmoved")
    if (CmpStr(check,"1") == 0)
        // do stuff
    endif
    SetWindow $s.winName userdata(curmoved)="0"
break

 

In reply to by chozo

Hi,

I implemented Chozo's suggestion albeit with a slight tweak to get it to compile.

String check = GetUserData(s.winName,0,"curmoved")

Needed to be changed to

String check = GetUserData(s.winName,"","curmoved")

because:

objID  is a string specifying the name of a control or graph trace. Use "" for a window or subwindow.

Andy