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.
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:
@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
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
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:
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:
/**
* 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;
}
I’ve found this explanation at MouseEvent::getCount():
So Mac’s “Natural Scrolling” can be active or not:
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).
@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()
it says returns the number of clicks… whilst in processing this number is always 1 never mind how far you scroll the wheel.
thts right! You can change it as you wish. for general purposes, I leave 1 in a float. You can change it as needed
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
// Assuming getCount() returns a range from -12 to 12
far = map(e.getCount(), -12, 12, -MAX_FAR, MAX_FAR);