Mouse with two scroll wheels

edited April 2017 in Questions about Code

I have a Logitech MX Master which has a vertical and horizontal scroll wheel. The following way of tracking wheel changes works only for the vertical wheel. Is there a way to do the same for the horizontal wheel?

void mouseWheel(MouseEvent event) {
  float e = event.getCount();
}

Thanks in advance, Alex

Answers

  • If you're on Mac,

    Horizontal scrolling is interpreted the same way as vertical scrolling, albeit with Shift held down

    Source - http://stackoverflow.com/questions/22851022/horizontal-scrolling-with-mousewheellistener

  • I searched a lot, but couldn't find out how Windows interprets horizontal mouse wheel scrolling.

  • edited April 2017

    @Lord_Of_The_Galaxy Thanks a lot for your help! I am in windows but want to give it a shot. How would I implement the code in your link?

  • edited April 2017

    I believe it won't work, but here it is anyway -

    void setup(){
      size(500, 500);
    }
    
    void draw(){
      background(0);
    }
    
    public void mouseWheel(MouseEvent me){
      if(me.isShiftDown())println("Horizontal scroll");
    }  
    
  • Why do you need the question mark at line 10?

  • Damn, you got me all excited with thinking there was some new nifty syntax to be discovered! :P

  • Unfortunately it doesn't work :/

  • @Lord_of_the_Galaxy It is not common to process info from the MouseEvent object... I haven't seen much of it anyways here in the forum. Do you happen to have a reference to it? (It will complement this post by providing a better insight to MEvnt handling)

    @Alex_Pr I will suggest doing a java + double scroll wheel search and see if anything alike have already being implemented in the Java universe. Whatever you find there, it could be use here. If Processing hasn't implemented it through their MouseEvent handling class, then you could submit a feature request.

    Kf

  • @Alex_Pr try testin it on a Mac system, if you have access to one. It should work. But, like I said, it won't work on Windows. One could try experimenting to figure out a solution.

    @kfrajer I just happen to know a bit of how Processing works internally, but I think it must be documented here - http://processing.github.io/processing-javadocs/core/

  • The best approach would be to use a bunch of println() statements and figure out what is the difference between a horizontal and vertical scroll wheel mouse event.

    http://processing.github.io/processing-javadocs/core/processing/event/MouseEvent.html

  • So it is documented (to some extent) over there.

  • @colouredmirrorball I have already tried a println(me) in Lord_Of_The_Galaxy's code but nothing is printed when I use the side scrollWheel. It does not recognize the horizontal scroll as an event

  • Now that's even worse :(

  • I am not sure if it will be supported by processing. For example:

    https://github.com/processing/processing/blob/master/core/src/processing/event/MouseEvent.java

    The MouseEvent only detects a wheel action. Does your second wheel triggers the following code at all?

    One attempt is:

    import processing.event.MouseEvent;
    
    void setup() {
      size(500, 500);
    }
    
    void draw() {
      background(0);
      if(frameCount % 15 ==0) println(.......................);
    }
    
    public void mouseWheel(MouseEvent me) {
       println(me.getAction());
      if (me.isShiftDown())println("Horizontal scroll");
    } 
    
    void mouseReleased(MouseEvent me){
      println(me.getAction()); 
    }
    
    void mouseClicked(MouseEvent me){
      println("***********"+me.getAction()); 
    }
    
    void mouseMoved(MouseEvent me){
      println(me.getAction());
      if(me.getAction()==MouseEvent.CLICK)
        println("CLICKED!");
    }
    

    Does your second wheel trigger the mouseWheel? Do you get code 8?

    I notice in the source code you can get to output UNKNOWN when calling get action. I wonder if one can have access to mouseEvent within draw and check if the second mouse wheel triggers the UNKNOWN action. If it does, then accessing the second wheel event could be possible. However, I don't know how to get access to the MouseEvent in draw(). I am guessing mouseEvent gets registered to the main thread (?). I will need to dig into the source code to see if it is possible to do this.... Or maybe somebody knows?

    void setup{....}
    
    void draw(){
    
        MouseEvent_object -> getAction()  ---> equals MouseEvent.UNKNOWN?
    
    }
    

    Kf

  • edited April 2017
    void setup(){
      size(....);//this time, it is a must that you call size() before, to prevent double registering
      registerMethod("mouseEvent", this);
    }
    
    void draw(){...}
    
    void mouseEvent(MouseEvent me){
      println(me.getAction());//it will print a number, though.
    }
    
  • We may need to look at the complete code to figure out what happens on horizontal scroll.

    Please test horizontal scroll on your mouse (use my code), and tell us what gets printed.

  • @kfrajer , @Lord_of_the_Galaxy none of the codes print anything when I use the horizontal scroll wheel.

  • Then apparently Java itself doesn't know of horizontal scroll wheel.

Sign In or Register to comment.