Page 2 of 3
Re: Keyboard shortcuts for mouse wheel
Posted: Sun Nov 17, 2019 10:55 am
by BarryG
Dude, try this. Just test -1 for up, and "else" for down:
Code: Select all
If OpenWindow(0,300,300,160,55,"MouseWheel",#PB_Window_SystemMenu)
TextGadget(0,20,20,150,20,"Scroll the mouse wheel...")
Repeat
ev=WaitWindowEvent()
If ev=#WM_MOUSEWHEEL
dir=-(EventwParam()>>16)/#WHEEL_DELTA
Debug dir
If dir=-1 ; For both 64bit and 32bit
SetGadgetText(0,"UP")
Else ; -545 on 64bit, 1 on 32bit
SetGadgetText(0,"DOWN")
EndIf
EndIf
Until ev=#PB_Event_CloseWindow
EndIf
Re: Keyboard shortcuts for mouse wheel
Posted: Sun Nov 17, 2019 10:57 am
by Lord
It still shows "UP" or "DOWN" when using mouse wheel
under PB 5.71LTS(x64).
Re: Keyboard shortcuts for mouse wheel
Posted: Sun Nov 17, 2019 11:00 am
by BarryG
Isn't that the idea?
Re: Keyboard shortcuts for mouse wheel
Posted: Sun Nov 17, 2019 11:05 am
by Lord
Sorry, but I responded to Dude's posting:
Dude wrote:The code I posted above is no longer useful for 64bit PureBasic because it doesn't return negative or positive values for the wheel direction. Is there some sort of ">>" math trick to make it work again?
There was no other post then.
Re: Keyboard shortcuts for mouse wheel
Posted: Sun Nov 17, 2019 11:13 am
by BarryG
Lord wrote:I responded to Dude's posting
Okay, I understand now. (Edited my reply for you).
But when I tested Dude's code, it only showed "UP" for me as well on 5.71 64bit (Windows). So the code I posted was my fix. Strange that it shows UP/DOWN for you but not for us?
Re: Keyboard shortcuts for mouse wheel
Posted: Sun Nov 17, 2019 2:28 pm
by RASHAD
Search the forum for Cross Platform Mouse Wheel by
Shardik 
Re: Keyboard shortcuts for mouse wheel
Posted: Sun Nov 17, 2019 3:08 pm
by Shardik
Thank you RASHAD for remembering my
cross-platform example which demonstrates how to detect moving the mouse wheel up or down in a ListIconGadget.
My adapted code of Dude's original TextGadget example is very similar to BarryG's one but a little bit shorter and also working with PB 5.71 x86 and x64 on Windows:
Code: Select all
If OpenWindow(0,300,300,160,55,"MouseWheel",#PB_Window_SystemMenu)
TextGadget(0,20,20,150,20,"Scroll the mouse wheel...")
Repeat
ev=WaitWindowEvent()
If ev=#WM_MOUSEWHEEL
If (EventwParam() >> 16) & $8000
SetGadgetText(0,"DOWN")
Else
SetGadgetText(0,"UP")
EndIf
EndIf
Until ev=#PB_Event_CloseWindow
EndIf
Re: Keyboard shortcuts for mouse wheel
Posted: Sun Nov 17, 2019 5:31 pm
by Lord
BarryG wrote:...
But when I tested Dude's code, it only showed "UP" for me as well on 5.71 64bit (Windows). So the code I posted was my fix. Strange that it shows UP/DOWN for you but not for us?
Maybe it's because I'm still using Win7?
Re: Keyboard shortcuts for mouse wheel
Posted: Sun Nov 17, 2019 9:58 pm
by BarryG
Lord wrote:Maybe it's because I'm still using Win7?
That must be it, because I'm on Windows 10.
Re: Keyboard shortcuts for mouse wheel
Posted: Mon Nov 18, 2019 8:37 am
by Lord
Here on Win7 EventwParam() returns
Code: Select all
UP: $00780000 = %0000 0000 0111 1000 0000 0000 0000 0000
DOWN: $FF880000 = %1111 1111 1000 1000 0000 0000 0000 0000
So any Bit 20 to 31 can be testet.
What is it on Win10?
Re: Keyboard shortcuts for mouse wheel
Posted: Mon Nov 18, 2019 8:56 am
by BarryG
Windows 10, PureBasic 64-bit, EventwParam() = $78000 for up, $FF880000 for down (same as Win 7). Since both of these are positive numbers, Dude's test using "<0" and ">0" doesn't work for me; hence my example above that I had to use.
Re: Keyboard shortcuts for mouse wheel
Posted: Mon Nov 18, 2019 10:56 am
by Josh
All these codes have a problem. Not every mouse (mousewheel without grid) returns a value of 120 units. This value can be much finer, so the values have to be summed up:
Code: Select all
If OpenWindow(0,300,300,160,55,"MouseWheel",#PB_Window_SystemMenu)
TextGadget(0,20,20,150,20,"Scroll the mouse wheel...")
Repeat
ev=WaitWindowEvent()
If ev=#WM_MOUSEWHEEL
MouseWheelDelta + EventwParam() >> 16
While MouseWheelDelta >= 120
SetGadgetText(0,"UP")
MouseWheelDelta - 120
Wend
While MouseWheelDelta <= -120
SetGadgetText(0,"DOWN")
MouseWheelDelta + 120
Wend
EndIf
Until ev=#PB_Event_CloseWindow
EndIf
Re: Keyboard shortcuts for mouse wheel
Posted: Mon Nov 18, 2019 2:42 pm
by Lord
You don't have to rely on the value of transmitted data.
Just test if param is negativ then subtract 1, else add 1.
Afterwards you can decide what step size are neccessery.
For example a scrollbar can make 1 step or 10 or 50.
You don't have to be concerned about, what granularity
the mouse has.
Re: Keyboard shortcuts for mouse wheel
Posted: Mon Nov 18, 2019 4:11 pm
by Josh
@Lord
No, that's not right. If you have a high resolution mouse wheel, you can get 1, 3, 9, 19, 70 or any number of events in the area that normally corresponds to one notch on the mouse wheel. Then your ListIconGadget (or whatever) would jump 1, 3, 9, 19, 70 number of lines up or down, although it should only be one line. Using a high resolution mouse wheel, the number of sent events is a random value for you, only the summed up values will give you a reliable result independent of the mouse used.
The method with the summed up values is by the way:
- recommended by Microsoft
- used by Pb for the CanvasGadget
Of course, you don't always have to check for a value of 120. For example, if you use the standard Windows text editor, the text will always scroll four lines if you use a standard mouse with notches. If you create something like this yourself, you could also check to a value of 30, so the behavior remains the same for all mice, but the user of a mouse with a high-resolution wheel then has the additional advantage that he can scroll with the mouse wheel with fine operation also one single line.
Re: Keyboard shortcuts for mouse wheel
Posted: Tue Nov 19, 2019 10:12 am
by Lord
@Josh
My posting refers for example to a manually updated scrollbar.
You need only the direction up or down and the decide how
many steps you go up or down.
I should have written: "You don't have always to rely on the
value of transferred data."