# mouseWheel event.getCount OS difference

**URL:** <https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378>\
**Category:** Coding Questions\
**Created:** [May 19, 2019, 10:20am UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378 "2019-05-19T10:20:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mala](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mala](https://discourse.processing.org/u/mala)\
**Post date:** [May 19, 2019, 10:20am UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/1 "2019-05-19T10:20:09Z")

</div>

Has anyone any insight into why getCount on the mousewheel returns differently on OSX(10.14) to Windows(10) ?  
On OSX the code below will return a range from -12 to 12 dependent on how far the wheel is scrolled.  
On Windows I just get -1 or 1, no matter how far the wheel is scrolled.

```auto
void draw() {
}

void mouseWheel(MouseEvent event) {
  println(event.getCount());
}

```

Cheers,  
mala

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 19, 2019, 12:45pm UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/2 "2019-05-19T12:45:41Z")

</div>

I don’t have a Mac 🍎. But anyways, here’s my blind 🕶 attempt to convert the value returned by MouseEvent::**getCount()** to be always `-1` for scroll-up & `1` for scroll-down regardless the OS: 🤞

```auto
int count;

void mouseWheel(final MouseEvent e) {
  count = Integer.signum(e.getCount());
  if (platform == MACOSX) count *= -1;
  println(count);
}

void draw() {
  noLoop();
}

```

---

<div class="post-metadata">

**Author:** ![mala](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mala](https://discourse.processing.org/u/mala)\
**Post date:** [May 19, 2019, 2:20pm UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/3 "2019-05-19T14:20:48Z")

</div>

@GoToLoop, Thanks I can confirm that does work on OSX.

I should have been more clear in my original question though, as I was looking to do the opposite of your solution and make the code on Windows return the same way as the code on OSX does.

It seems to me that on OSX the OS or java? Is adding all the clicks of the scroll wheel up and that is what the mouseEvent.getCount() is getting… this total then seems to be reset if there is no scroll event for a certain amount of time or the direction scrolled is changed.  
I guess I can build for the Windows version some code that will add up all the 1 & -1 and run a timer so this total would be reset if no scroll event occurs within a certain time.

I would really like to understand why the same mouseEvent returns different results on a different OS, but google hasn’t pointed me in the right direction yet 🙁

---

<div class="post-metadata">

**Author:** ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)\
**Post date:** [May 19, 2019, 3:25pm UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/4 "2019-05-19T15:25:10Z")

</div>

Hi @mala  
here’s how i approached this.  
this will return a range from -12 to 12. and reset if no wheel for certain amount of the time

```auto
void setup() {
  size(640, 200);
  fill(255);
  noStroke();
}
void draw() {
  background(51);
  float rectW = far * 10;
  text((int)far, width/2 + far * 10, height/2- 5);
  rect(width/2, height/2, rectW, 30);
  
  // Reset
  far = millis() - start > 1000 ? 0 : far;
}

float far = 0; //wheel traveled
float multiplier = 1f; // wheel smoothness
int start; 
void mouseWheel(MouseEvent e) {
  start = millis();
  far = constrain(far + e.getCount() * multiplier, -12, 12);
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 19, 2019, 3:50pm UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/5 "2019-05-19T15:50:36Z")

</div>

Any particular reason for using `float` instead of `int` to store **millis()** & **getCount()**? 🤔

---

<div class="post-metadata">

**Author:** ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)\
**Post date:** [May 19, 2019, 5:48pm UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/6 "2019-05-19T17:48:28Z")

</div>

yes 😃  
since getCount() is just return -1 and 1, i equipped it with smoothness (how far each wheel click should go). by tweaking the smoothness we can adjust scrolling detail  
for that millis() it is already stored in int.  
hope that make sense

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 20, 2019, 2:35am UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/7 "2019-05-20T02:35:23Z")

</div>

> [@humayung](#):
>
> By tweaking the smoothness we can adjust scrolling detail…

By smoothness you mean your constant _multiplier_, right?  
But currently, it’s just the integer value `1` in your code.  
So if we replace all `float` declarations w/ `int`:

```auto
int rectW = far * 10;
int far = 0;
int multiplier = 1;

```

Your sketch still works. 😀

Anyways, I’ve modded your sketch to use `int`. Here it comes: 😹

```auto
/**
 * Wheel Millis Count (v2.0.1)
 * Humayung (2019/May/19)
 * mod by GoToLoop
 *
 * https://Discourse.Processing.org/t/
 * mousewheel-event-getcount-os-difference/11378/7
 */

static final int MAX_MILLIS = 1000, MAX_FAR = 12, MULT = 1;
static final int MULT_W = 10, H = 30, OFFSET_H = -5;
static final color BG = 070, FG = -1;

int start, far;

void setup() {
  size(300, 100);
  fill(FG);
  noStroke();
}

void draw() {
  if (millis() - start >= MAX_MILLIS) far = 0;

  final int cx = width >> 1, cy = height - H >> 1;
  final int w = far * MULT_W, tx = w + cx - int(far > 0)*MULT_W;

  background(BG);
  text(far, tx, cy + OFFSET_H);
  rect(cx, cy, w, H);
}

void mouseWheel(final MouseEvent e) {
  start = millis();
  far = constrain(e.getCount()*MULT + far, -MAX_FAR, MAX_FAR);
  if (platform == MACOSX) far *= -1;
}

```

---

<div class="post-metadata">

**Author:** ![mala](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mala](https://discourse.processing.org/u/mala)\
**Post date:** [May 20, 2019, 9:43am UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/8 "2019-05-20T09:43:29Z")

</div>

@humayung Thank you. Your solution is pretty much what I was thinking and works on OSX and Windows.

@GoToLoop This line :

`if (platform == MACOSX) far *= -1;`

breaks your version of humayungs code on OSX.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 20, 2019, 10:27am UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/9 "2019-05-20T10:27:46Z")

</div>

> [@mala](#):
>
> breaks your version of humayungs code on OSX.

Funny, I’ve heard once Mac OS would **getCount()** the opposite of Windows & Linux. 🍎

But I don’t have a Mac. So just erase that `if (platform == MACOSX) far *= -1;` checking. 😛

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 20, 2019, 10:59am UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/10 "2019-05-20T10:59:37Z")

</div>

I’ve found this explanation at MouseEvent::**getCount()**: 🖱

> <https://github.com/processing/processing/blob/processing-0269-3.5.3/core/src/processing/event/MouseEvent.java#L107-L114>

So Mac’s “Natural Scrolling” can be active or not: 📜

> <https://stackoverflow.com/questions/7074882/java-how-to-get-the-scrolling-method-in-os-x-lion>

However, I still dunno whether “Natural Scrolling” is on by default. ❔

P.S.: From what I’ve found out so far, “natural scrolling” seems to be on by default since MacOS Lion (2011): 😒

`Scrolling is reversed by default, to act more like a touch screen device, so that content moves in the direction of finger movement on touch-pad or mouse (with the scrollbar moving in the opposite direction), rather than the scrollbar moving in the direction of finger movement (with the content moving in the opposite direction).`

> **[Mac OS X Lion | User interface changes](https://en.wikipedia.org/wiki/Mac_OS_X_Lion#User_interface_changes)**
>
> 1.Redesigned Aqua user interface elements, including buttons and progress bars. The red, yellow, and green buttons in the window decorations have also been made smaller, with a slightly changed design. |
> 2.Flexible window resizing from any corner or edge of the window, similar to window resizing in Microsoft Windows and many window managers for X11. |
> 3.The metal finish has also been slightly altered. It is a lighter shade of grey and features a speckled texture.\[citation needed\] |

---

<div class="post-metadata">

**Author:** ![mala](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mala](https://discourse.processing.org/u/mala)\
**Post date:** [May 20, 2019, 11:52am UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/11 "2019-05-20T11:52:20Z")

</div>

@GoToLoop Yes I’ve tested with natural scrolling on & off , but all this does is reverse the direction not change the count.  
If I’m reading the java docs correctly then I think this is actually an issue with Processing on Windows, if you look at “getWheelRotation()” here -\> [https://docs.oracle.com/javase/6/docs/api/java/awt/event/MouseWheelEvent.html#getWheelRotation()](https://docs.oracle.com/javase/6/docs/api/java/awt/event/MouseWheelEvent.html#getWheelRotation())  
it says returns the **number** of clicks… whilst in processing this number is always 1 never mind how far you scroll the wheel.

---

<div class="post-metadata">

**Author:** ![humayung](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/humayung/32/6089_2.png) [@humayung](https://discourse.processing.org/u/humayung)\
**Post date:** [May 20, 2019, 1:10pm UTC](https://discourse.processing.org/t/mousewheel-event-getcount-os-difference/11378/12 "2019-05-20T13:10:45Z")

</div>

> [@GoToLoop](#):
>
> By smoothness you mean your constant _multiplier_ , right?  
> But currently, it’s just the integer value `1` in your code.  
> So if we replace all `float` declarations w/ `int` :
> 
> ```auto
> 
> ```

thts right! You can change it as you wish. for general purposes, I leave 1 in a float. You can change it as needed 🙂

> [@GoToLoop](#):
>
> if (platform == MACOSX) far \*= -1;

In my perspective, since on osx the `getCount()` returns a range (@mala said, i dont have a mac too) , `map()` it to desired range.  
look like thats `far *= -1` just flipped the direction.

so, it might be

```auto
// Assuming getCount() returns a range from -12 to 12
far = map(e.getCount(), -12, 12, -MAX_FAR, MAX_FAR);

```
