PureBasic Forum
https://www.purebasic.fr/english/

Keyboard shortcuts for mouse wheel
https://www.purebasic.fr/english/viewtopic.php?f=3&t=69882
Page 3 of 3

Author:  Josh [ Tue Nov 19, 2019 10:30 am ]
Post subject:  Re: Keyboard shortcuts for mouse wheel

@Lord

If you don't want to understand, I can't help you either. But if you write an application that uses the scroll wheel and you want to share it with others, be fair and include the following warning to your app:

"Attention, this application is not suitable for a mouse with a high resolution mouse wheel."

Author:  Lord [ Wed Nov 20, 2019 2:23 pm ]
Post subject:  Re: Keyboard shortcuts for mouse wheel

Josh wrote:
...
If you don't want to understand, I can't help you either. But if you write an application that uses the scroll wheel and you want to share it with others, be fair and include the following warning to your app:

"Attention, this application is not suitable for a mouse with a high resolution mouse wheel."
There's no need for this.

You don't always need to know what resolution your mouse has.
Sometimes it is just only neccessary to know witch direction is wanted:
Code:
EnableExplicit

Structure Datas
  WW.i
  WH.i
  ScrollbarV.Point
  ScrollbarVW.i
  ScrollbarVH.i
  ScrollbarH.Point
  ScrollbarHW.i
  ScrollbarHH.i
  Mouse.Point
EndStructure
Define Positions.Datas
With Positions
  \WW            = 640
  \WH            = 458
  \ScrollbarVW   = 20
  \ScrollbarVH   = \WH-20
  \ScrollbarV\x  = \WW-\ScrollbarVW
  \ScrollbarV\y  = 0
  \ScrollbarHH   = 20
  \ScrollbarHW   = \WW-20
  \ScrollbarH\x  = 0
  \ScrollbarH\y  = \WH-\ScrollbarHH
EndWith

Define Event.i

Procedure myResize()
  Shared Positions
  With Positions
    \WW=WindowWidth(1)
    \WH=WindowHeight(1)
    \ScrollbarVH   = \WH-20
    \ScrollbarHW   = \WW-20
    \ScrollbarV\x  = \WW-\ScrollbarVW
    \ScrollbarH\y  = \WH-\ScrollbarHH
    ResizeGadget(1, \ScrollbarV\x, #PB_Ignore, #PB_Ignore, \ScrollbarVH)
    ResizeGadget(2, #PB_Ignore, \ScrollbarH\y, \ScrollbarHW, #PB_Ignore)
  EndWith 
EndProcedure
Procedure Scroll(Direction)
  Shared Positions
  Protected.i x, y, Value, Stepsize
  x=WindowMouseX(1)
  y=WindowMouseY(1)
  Stepsize=1
  If GetAsyncKeyState_(#VK_CONTROL)
    Stepsize=(GetGadgetAttribute(1, #PB_ScrollBar_Maximum)-GetGadgetAttribute(1, #PB_ScrollBar_Minimum))/10
  EndIf
  With Positions
    If x>=\ScrollbarV\x
      If y<=\ScrollbarVH
        SetGadgetAttribute(1, #PB_ScrollBar_PageLength, Stepsize)
        If Direction
          Value=-1*Stepsize
        Else
          Value=1*Stepsize
        EndIf
        SetGadgetState(1, GetGadgetState(1)+Value)
      EndIf
    EndIf
    If y>=\ScrollbarH\y
      If x<=\ScrollbarHW
        SetGadgetAttribute(2, #PB_ScrollBar_PageLength, Stepsize)
        If Direction
          Value=-1*Stepsize
        Else
          Value=1*Stepsize
        EndIf
        SetGadgetState(2, GetGadgetState(2)+Value)
      EndIf
    EndIf
  EndWith
EndProcedure

With Positions
  OpenWindow(1, 10, 10, \WW, \WH, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget)
  ScrollBarGadget(1, \ScrollbarV\x, \ScrollbarV\y, \ScrollbarVW, \ScrollbarVH, 1, 100, 1, #PB_ScrollBar_Vertical)
  ScrollBarGadget(2, \ScrollbarH\x, \ScrollbarH\y, \ScrollbarHW, \ScrollbarHH, 1, 100, 1)
EndWith

BindEvent(#PB_Event_SizeWindow, @myResize())

Repeat
  Event=WaitWindowEvent()
  If Event=#WM_MOUSEWHEEL
    GetAsyncKeyState_(#VK_CONTROL)
    Scroll((EventwParam()>>31)+1)
  EndIf
 
Until Event=#PB_Event_CloseWindow

But it's fine if you got a highresolution mouse and want to play with it. :wink:

Author:  Josh [ Wed Nov 20, 2019 3:21 pm ]
Post subject:  Re: Keyboard shortcuts for mouse wheel

@Lord
You just don't get it. Your nice example is nothing than unnecessary SchnickSchnack for this problem, because your basic mistake lies simply in your event loop:
Code:
Repeat
  Event=WaitWindowEvent()
  If Event=#WM_MOUSEWHEEL
    Scroll((EventwParam()>>31)+1)
  EndIf
Until Event=#PB_Event_CloseWindow

As I wrote before, you have no influence, when and how often a high resolution mousewheel fires an event. Only if the sum of the values in EventwParam() reaches a value of 120, your mouse wheel has the rotation angle back, which normally corresponds to a grid at the mousewheel.

Just a simple example: If you want to use the mouse wheel as middle mouse button, a high-resolution mouse wheel will surely fire several #WM_MOUSEWHEEL events, because the mouse wheel is also turned minimally when pressed. Then EventwParam() could look like this:

-3
+4
+2
-2

In this example your program already receives four events, your display will jump wildly up and down, although the user of your app only wanted to press the middle mouse button.


Lord wrote:
But it's fine if you got a highresolution mouse and want to play with it. :wink:
Wow, what ignorance. Maybe it should come in your consciousness that there are mice with high-resolution mouse wheels and if a programmer wants to call himself a programmer, then he should also consider this, especially if it is feasible with few additional lines of code. Mice with high-resolution mouse wheels are not only used by gamers, they are also used in CAD, which has absolutely nothing to do with playing.


But if you think that Microsoft is writing useless stuff, because you know better and you think that Fred has no idea that he has built this crap into the CanvasGadget, then just let it go.

Author:  Lord [ Wed Nov 20, 2019 4:47 pm ]
Post subject:  Re: Keyboard shortcuts for mouse wheel

I just don't agree with you. That's all.
Josh wrote:
...
If you don't want to understand, I can't help you either.
...
Josh wrote:
But if you think that Microsoft is writing useless stuff, because you know better and you think that Fred has no idea that he has built this crap into the CanvasGadget, then just let it go.
And this disqualifies you for further answers
or even reading of your postings.
Have a nice day.

Author:  Dude [ Fri Nov 29, 2019 12:45 am ]
Post subject:  Re: Keyboard shortcuts for mouse wheel

BarryG wrote:
Dude, try this. Just test -1 for up, and "else" for down

Thank you, it works on 64bit for me now. :)

Page 3 of 3 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/