Posts: 1,006
Threads: 330
Joined: Mar 2007
Hello Gintaras,
Hope all is well with you in this crazy year!
I have a need to set up a wait statement for MouseWheel (either direction). I am surprised that this never came up for me before. I couldn't find this in help/forum - maybe too lower-level?
Thanks for any help,
S
Posts: 12,097
Threads: 142
Joined: Dec 2002
04-07-2021, 04:22 PM
(This post was last modified: 04-07-2021, 04:25 PM by Gintaras.)
Function WaitForMouseWheel
;/
function timeS direction [flags] ;;direction: 1 forward, -1 backward, 0 any; flags: 1 block event
;Waits for mouse wheel forward or backward.
;timeS - 0 or timeout. Error on timeout.
opt noerrorshere 1
__Handle ev=CreateEvent(0 0 0 0)
__WindowsHook hook=SetWindowsHookEx(WH_MOUSE_LL &sub.Hook_WH_MOUSE_LL _hinst 0)
opt waitmsg 1
wait timeS H ev
#sub Hook_WH_MOUSE_LL v
function# nCode message MSLLHOOKSTRUCT&m
if(nCode<0) goto gNext
if message=WM_MOUSEWHEEL
,int v=m.mouseData
,if direction=0 or (direction>0 and v>0) or (direction<0 and v<0)
,,SetEvent ev
,,if(flags&1) ret 1
;gNext
ret CallNextHookEx(0 nCode message &m)
Also QM has mouse wheel triggers.
Posts: 1,006
Threads: 330
Joined: Mar 2007
Thank you for replying so quickly with a solution . Sorry, it has taken me this long to test and thank you.
It works but I made modification below so as to work with less than 1 sec (doubles like 0.5, 0.3, as in other wait statements).
Also, I wanted to make it return the value of whether mousewheel forward or backward. I do not understand the CreateEvent, SetWindowsHookEx, MSLLHOOKSTRUCT type functions/arguments very well. I know I should since hooking and subclassing, etc, is the basis of so much of the magic of QM! Perhaps at one point you could comment such a function with explanations or perhaps there is already a good explanation that may be available online or in forum or in QM Help.
In any case, I could only figure out how to do it with a thread integer variable as ret in main waitfunction, set in subfunction and used in calling function to direct subsequent actions. I know it is better practice to try and avoid globals/thread functions when possible and return explicit function variables or pointers. But as above, I couldn't quite figure it out. Here is my best attempt (does work though!):
Thanks again!,
S
Function WaitForMouseWheel
;/
function# ^waitMaxS direction [flags] ;;direction: 1 forward, -1 backward, 0 any; flags: 1 block event
;Waits for mouse wheel forward or backward.
;waitMaxS - 0 or timeout. Error on timeout. accepts less than 1 sec as decimal e.g. 0.5
;returns -1 for mousewheel backward, 1 for mousewheel forward e.g.
int- mwDirection
opt noerrorshere 1
__Handle ev=CreateEvent(0 0 0 0)
__WindowsHook hook=SetWindowsHookEx(WH_MOUSE_LL &sub.Hook_WH_MOUSE_LL _hinst 0)
opt waitmsg 1
wait waitMaxS H ev
if mwDirection > 0; ret 1
if mwDirection < 0; ret -1
ret mwDirection
#sub Hook_WH_MOUSE_LL v
function# nCode message MSLLHOOKSTRUCT&m
if(nCode<0) goto gNext
if message=WM_MOUSEWHEEL
,int v=m.mouseData
,mwDirection = v
,if direction=0 or (direction>0 and v>0) or (direction<0 and v<0)
,,SetEvent ev
,,if(flags&1) ret 1
;gNext
ret CallNextHookEx(0 nCode message &m)
Posts: 12,097
Threads: 142
Joined: Dec 2002
04-12-2021, 05:30 PM
(This post was last modified: 04-12-2021, 05:35 PM by Gintaras.)
Use local variable.
Function WaitForMouseWheel
;/
function# ^timeS direction [flags] ;;direction: 1 forward, -1 backward, 0 any; flags: 1 block event
;Waits for mouse wheel forward or backward.
;Returns: 1 forward, -1 backward.
;timeS - 0 or timeout. Error on timeout.
int R
opt noerrorshere 1
__Handle ev=CreateEvent(0 0 0 0)
__WindowsHook hook=SetWindowsHookEx(WH_MOUSE_LL &sub.Hook_WH_MOUSE_LL _hinst 0)
opt waitmsg 1
wait timeS H ev
if R > 0; ret 1
if R < 0; ret -1
#sub Hook_WH_MOUSE_LL v
function# nCode message MSLLHOOKSTRUCT&m
if(nCode<0) goto gNext
if message=WM_MOUSEWHEEL
,int v=m.mouseData
,if direction=0 or (direction>0 and v>0) or (direction<0 and v<0)
,,SetEvent ev
,,R = v
,,if(flags&1) ret 1
;gNext
ret CallNextHookEx(0 nCode message &m)
Posts: 1,006
Threads: 330
Joined: Mar 2007
|