Keyboard shortcuts for mouse wheel

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1184
Joined: Sat Feb 13, 2010 3:45 pm

Re: Keyboard shortcuts for mouse wheel

Post by Josh »

@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."
sorry for my bad english
Lord
Enthusiast
Enthusiast
Posts: 744
Joined: Tue May 26, 2009 2:11 pm

Re: Keyboard shortcuts for mouse wheel

Post by Lord »

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: Select all

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:
Image
User avatar
Josh
Addict
Addict
Posts: 1184
Joined: Sat Feb 13, 2010 3:45 pm

Re: Keyboard shortcuts for mouse wheel

Post by Josh »

@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: Select all

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.
sorry for my bad english
Lord
Enthusiast
Enthusiast
Posts: 744
Joined: Tue May 26, 2009 2:11 pm

Re: Keyboard shortcuts for mouse wheel

Post by Lord »

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.
Last edited by Lord on Thu Nov 21, 2019 2:07 pm, edited 1 time in total.
Image
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Keyboard shortcuts for mouse wheel

Post by Dude »

BarryG wrote:Dude, try this. Just test -1 for up, and "else" for down
Thank you, it works on 64bit for me now. :)
Post Reply