Mouse events when dragging a cursor
Claudioez
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.
displayhelptopic "Cursors - Moving Cursor Calls Function"
February 22, 2018 at 08:09 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
February 22, 2018 at 12:46 pm - Permalink
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.
February 22, 2018 at 11:34 pm - Permalink
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.
February 23, 2018 at 12:56 am - Permalink
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).
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
February 23, 2018 at 07:09 am - Permalink
Hmm... I wrote a very simple window hook function:
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
February 23, 2018 at 11:26 am - Permalink
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
February 23, 2018 at 12:14 pm - Permalink
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
March 14, 2022 at 03:42 pm - Permalink
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.:
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.:
String check = GetUserData(s.winName,0,"curmoved")
if (CmpStr(check,"1") == 0)
// do stuff
endif
SetWindow $s.winName userdata(curmoved)="0"
break
March 14, 2022 at 09:08 pm - Permalink
In reply to If you don't mind the hook… 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
because:
objID is a string specifying the name of a control or graph trace. Use "" for a window or subwindow.
Andy
February 7, 2024 at 08:27 am - Permalink