It is currently Sat Aug 15, 2020 8:34 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 35 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Sun Nov 17, 2019 10:55 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 955
Dude, try this. Just test -1 for up, and "else" for down:

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Sun Nov 17, 2019 10:57 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 652
:?: :?: :?:
It still shows "UP" or "DOWN" when using mouse wheel
under PB 5.71LTS(x64).

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Sun Nov 17, 2019 11:00 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 955
Isn't that the idea?


Last edited by BarryG on Sun Nov 17, 2019 11:15 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Sun Nov 17, 2019 11:05 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 652
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.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Sun Nov 17, 2019 11:13 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 955
Lord wrote:
I responded to Dude's posting

Okay, I understand now. (Edited my reply for you). :wink:

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?


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Sun Nov 17, 2019 2:28 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3654
Search the forum for Cross Platform Mouse Wheel by Shardik :)

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Sun Nov 17, 2019 3:08 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1753
Location: Germany
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Sun Nov 17, 2019 5:31 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 652
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?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Sun Nov 17, 2019 9:58 pm 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 955
Lord wrote:
Maybe it's because I'm still using Win7?

That must be it, because I'm on Windows 10.


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Mon Nov 18, 2019 8:37 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 652
Here on Win7 EventwParam() returns
Code:
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?

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Mon Nov 18, 2019 8:56 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 955
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Mon Nov 18, 2019 10:56 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 1128
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:
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

_________________
sorry for my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Mon Nov 18, 2019 2:42 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 652
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.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Mon Nov 18, 2019 4:11 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 1128
@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.

_________________
sorry for my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard shortcuts for mouse wheel
PostPosted: Tue Nov 19, 2019 10:12 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 652
@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."

_________________
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 35 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye