Forums > MaxMSP

ol.mousewheel


Oct 07 2012 | 3:20 pm

HI,
do you know how it works ? i try with the helper… but nothing appends. thanks for your help.
you can download it here :
http://cycling74.com/forums/topic.php?id=33651&bb_attachments=163416&bbat=2312

Oct 07 2012 | 6:04 pm

ok, thanks a lot, Oli Larkin say :No… Jit.window reports mouse wheel messages in max6 which meant I didnt need an extra object

i ‘ve try to use this, i can read the value of the wheel ( speed ) but i don’t arrive to use it… i connect the result in a flonum…and nothing…

Nov 21 2013 | 10:40 am

Hi there. I know that ol.mousewheel doesn’t work on the Mac anymore, but would like to let you know that I’ve tried it on Windows 7 (Pro 64) with Max 6.1.5 (32 bit) and it’s working fine there…

On a related note, now I really need a solution on the Mac side… is there any cross-platform solution to get the mousewheel information? It’s really unfortunate that such a basic and useful feature isn’t supported by [mousestate] or other builtin object (with jit.window’s exception). We can connect arduinos, kinects and wiimotes, but can’t have access to the mousewheel or its additional buttons (and no, [hi] doesn’t count, as the keyboard and mouse are not available on the Windows side…).

Apr 22 2016 | 1:36 am

Just in case somebody is looking for a mousewheel solution for any kind of ui object:

jnativehook (https://github.com/kwhat/jnativehook) implemented as a mxj java external works well on Windows 10 and Max/MSP 7

Apr 22 2016 | 1:20 pm

Hello Julius,

I think its a very useful solution that you just share with us, thank you a lot!

Do you or maybe the other MMJ users know how to implement this into a patch? As a beginner I really do not know where to start…
Looking forward to get this working.

Thank for your input,
All the best,

Alfredo

Apr 25 2016 | 2:50 am

hi Alfredo

1) Download the "JNativeHook-2.0.3.zip" from this Link: "https://github.com/kwhat/jnativehook/releases" Unzip it. You will get a .jar file.

2) Compile the java source code in the following post. You will get a .class file.

3) Now you have to tell MAX/MSP where to find the jar file and the .class file . This means that you edit the "max.java.config.txt" file, adding the path to both files to this .txt file. This .txt file can be found in: "C:\Program Files\Cycling ’74\Max 7\resources\packages\max-mxj\java-classes". Which lines to edit is described in the txt file itself.

4) Restart MAX/MSP

5) Create a mxj Object and enter"globalMousewheel" as its first argument. Send this object a "start" message" and it will output the mousewheel data.

Hope this helps.
julius

Apr 25 2016 | 2:53 am

import java.util.logging.Level;
import java.util.logging.Logger;

import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;

import org.jnativehook.mouse.NativeMouseWheelEvent;
import org.jnativehook.mouse.NativeMouseWheelListener;

import com.cycling74.max.Atom;
import com.cycling74.max.MaxObject;

public class globalMousewheel extends MaxObject implements NativeMouseWheelListener{

public globalMousewheel(Atom[] args) {
//declareAttribute("autostart", null, "autoStart");
declareIO(1, 1);
}

@Override
public void nativeMouseWheelMoved(NativeMouseWheelEvent e) {
outlet(0, e.getWheelRotation());

}

public void start(){
// Get the logger for "org.jnativehook" and set the level to warning.
// Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
// logger.setLevel(Level.WARNING);

//no log message please
final Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
logger.setLevel(Level.OFF);

//start NativeHook
try {
GlobalScreen.registerNativeHook();
}
catch (NativeHookException ex) {
post("There was a problem registering the native hook.");
post(ex.getMessage());
}
//start the listener
GlobalScreen.addNativeMouseWheelListener(this);
}

public void stop(){
//stop the listener
GlobalScreen.removeNativeMouseWheelListener(this);
//Stop the nativeHook
try {
GlobalScreen.unregisterNativeHook();
}
catch (NativeHookException ex) {
post("There was a problem unregistering the native hook.");
post(ex.getMessage());
}
}

}

Apr 25 2016 | 3:43 pm

Thank you a lot, Julius!

I’m on mac an did try to compile the code above, but get some errors at the end.

After check the code online I have same result:

http://ideone.com/dS5mXC

I’m on Mac, does it have to do with it? Or else?

Thank you again,
All the best,

Alfredo

Apr 26 2016 | 12:03 am

hi Alfredo

I think the best way to make this work is to setup Eclipse for Max/MSP Development as described here:

http://www.evsc.net/tech/how-to-jitter-java-objects

After this put the jnativehook.jar in the lib folder of your eclipse project and add it to the java build path. (Google: eclipse add external jar to build path)

I think that the reason why you get the error messages is that you named the .java file something other than the class Name "globalMousewheel". In Java the classname has to be the same as the filename. Even if this is the case you will get further error mesages once you corrected this: Have a look at the "import" statements at the beginning of the code. Several classes that are stored in the max.jar and the nativehook.jar are imported. When compiling the code the compiler needs to know where to find this jar files. Thats the reason why you have to put them on the build path in Eclipse.

Please let me know how much java expierence you have got. If you have little or no java expierence i would post other, more detailed instructions.

julius

Apr 26 2016 | 6:57 am

Hello Julius,

my java experience is 0+, so I absolutely have to figure things out… and after few hours I could compile "something", please take a look at the attachment.

I’ve finished steps below:
1) Installed Ecliplse (eclipse-java-mars-2-macosx-cocoa-x86_64 and jdk-7u79-macosx-x64)
2) Made a new Java project with title "JNativeHook" (JavaSE-1.7 ex. enviroment)
3) Unpacked JNativeHook-2.0.3.zip and took only the jnativehook-2.0.3.jar from the package and putted in the "lib" folder of the relevant project’s workspace
4) Added jitter.jar and max.jar from Max 6 dir in the same folder
5) Added those 3 files to the "Referenced Libraries" by "Add to Build Path" function in Eclipse
6) Made a new class file with name "globalMousewheel" in the "JNativeHook/src" source folder with modifiers "Public"
7) Pasted your script complete in the globalMousewheel.java tab of Eclipse and compiled the .class
8) added a line max.dynamic.class.dir /Users/itsprobablyme/Documents/workspace/JNativeHook/bin and max.dynamic.jar.dir /Users/itsprobablyme/Documents/workspace/JNativeHook/lib into the max.java.config.txt and safed the file.
9) restarted Max and added a new [mxj globalMousewheel]
10) get an error:
MXJ System CLASSPATH:
/Applications/Max 6.1/Cycling ’74/java/lib/jitter.jar
/Applications/Max 6.1/Cycling ’74/java/lib/jode-1.1.2-pre-embedded.jar
/Applications/Max 6.1/Cycling ’74/java/lib/max.jar
MXJClassloader CLASSPATH:
/Applications/Max 6.1/Cycling ’74/java/classes/
/Users/itsprobablyme/Documents/workspace/JNativeHook/lib/jitter.jar
/Users/itsprobablyme/Documents/workspace/JNativeHook/lib/jnativehook-2.0.3.jar
/Users/itsprobablyme/Documents/workspace/JNativeHook/lib/max.jar
/Users/itsprobablyme/Documents/workspace/JNativeHook/bin
Jitter initialized
Jitter Java support installed
java.lang.UnsupportedClassVersionError: globalMousewheel : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at com.cycling74.max.MXJClassLoaderImpl.doLoadClass(MXJClassLoaderImpl.java:119)
at com.cycling74.max.MXJClassLoader.loadClazz(MXJClassLoader.java:88)
Could not load class ‘globalMousewheel’

Im on Mac 10.9.5 with Max 6.1/Java 1.8.0_91

What would you suggest next?

Thank you for the patience,
All the best,

Alfredo

Apr 26 2016 | 6:59 am

PS..
oups, no permission to upload .class files here…

Apr 26 2016 | 10:29 am

hi Alfredo

Max is currently bound to Java for OS X the maximum supported Java version is 1.6 (update 65). This means Max can’t handle mxj classes compiled with Java 1.7 or later. Read about this here:

https://cycling74.com/wiki/index.php?title=Java_on_OS_X_10.9_%28and_later%29

It is quite easy in Eclipse to set up your project to use a specific Java version: Right click on your nativehook project :: properties::java ::compiler. Choose the 1.6 Apple Java Version.

Let me know if this did the trick
julius

Apr 26 2016 | 1:55 pm

Grand Applause, Julius!

It works! The problems was: the wrong version (1.7) and the different names in .jar and .class.

I go to explore the .md files and back with an example.

Thank you for the patience,
With compliments,

Alfredo

Apr 27 2016 | 12:51 am

hi Alfredo

Super that you achieved this.

One more thing: When you use the "globalMouswheel" object in a patch, make sure it has a "closebang" object with a message Object ("stop") connected to it. That way nativehhook will shut down when you close your patch, otherwise you will have a running ghost process in your system.

julius

Viewing 14 posts - 1 through 14 (of 14 total)

Forums > MaxMSP