Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wait For MouseWheel
#1
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
#2
Function WaitForMouseWheel
Code:
Copy      Help
;/
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.
#3
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
Code:
Copy      Help
;/
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)
#4
Use local variable.

Function WaitForMouseWheel
Code:
Copy      Help
;/
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)
#5
perfect. thanks!
S


Forum Jump:


Users browsing this thread: 1 Guest(s)