GithubHelp home page GithubHelp logo

tulskiy / jkeymaster Goto Github PK

View Code? Open in Web Editor NEW
233.0 233.0 45.0 467 KB

A library for registering global hotkeys in java with JNA. The goal is to support X11-based platforms, Windows and MacOSX

License: GNU Lesser General Public License v3.0

Java 100.00%

jkeymaster's Issues

Listen PREENTSCREEN key doesn't work

Platform: win 7 x64

My code:

            Provider provider = WindowsProvider.getCurrentProvider(false);
            provider.register(KeyStroke.getKeyStroke("shift PRINTSCREEN"), new HotKeyListener() {
                @Override
                public void onHotKey(HotKey hotKey) {

                    System.out.println("asdasdssdf");
                }
            });

The "Released" and "Down" seems not working properly

Thanks for supplying this library, it looks really nice :)

Here's my working example:

    Provider provider = Provider.getCurrentProvider(false);

    HotKeyListener keyListener = new HotKeyListener() {
        @Override
        public void onHotKey(HotKey key) {
            System.out.println("Hot Key Pressed: " + key);
        }
    };

    provider.register(KeyStroke.getKeyStroke('M',KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK),keyListener);
    provider.register(KeyStroke.getKeyStroke('A',KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK,true),keyListener);
    provider.register(KeyStroke.getKeyStroke('M',KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK,true),keyListener);

However, at my last register statement, I got "WARNING: Could not register HotKey: shift ctrl released M. Error code: -9878". Additionally, the release event was populated, when I simply press the key without actually releasing it.

I'm using Java6 on Mac

Mapping keys can recurse forever

Firstly, the key capture works really well.

However, I am mapping keys to other keys - so if I listen for 'f' and then use java.awt.robot to (robot) type 'g', this works fine. But if I listen for 'g' and (robot) type 'f', then the events seesaw back and forth forever.

This is also an issue if you sometimes need to pass through a key event (i.e. ignore it).

Thinking about this for a (short) while, how about an option to add jkeymaster ignored key events to the event queue. This might be through a sub class of the usual key events. Then, a capture of 'f' could raise an ignorable 'g' event - when ignored, 'g' would be typed as usual, by bypassing the event handler. The 'g' capture could also generate an ignorable 'f' key event.

of course, I have no idea what is going on 'under the bonnet' - so this could be a terrible idea...

For the second case (optional pass through), I can see two other options:

  1. Allow the key listener to 'restore' a keyevent back into the event queue, so it proceeds to the next listener/s (so it doesn't get called again)..
  2. Add a Conditional Key Listener that has the option of consuming the event - or leaving it in the queue - the equivalent of setHandled(true). Again, this only helps with pass through.

For the first case, the previous options could also work for simple cases with custom code to handle the case of 'ignore events I have just raised'.

Is this something that makes sense for jkeymaster to handle?

Help with put another github project to maven repository

Sorry to put my question her in an issue. But i don't know how to get in conversation with you on another way.

concret it's this project: marcojakob/javafx-ui-sandbox#8

its also a good part, as yours, but it´s not available on an maven repository.

I would need your code and his code for a study project :( Could you stay in conversation with him or aks him for put his project for him on maven. Perhaps you could explore him what he should do to get it on an maven repository.

Sorry for my bad english :(

X11 Media Key NullPointerException

I'm having a little problem with MediaKeys on X11. When any event is fired, I'm getting a NullPointerException from X11Provider Line 120. I think this problem occurs, because it's trying to get isOnKeyRelease from keyStroke, which isn't initialized for MediaKeys.

A bug for run in MacOSX 10.5.8

Hello:

    I'm sorry to tell you, it seems that I found a bug when jKeymaster run in real macbook. So now ,I will list this bug.

    first, i open this project in eclipse, run the AWTTest.java. and then Grab the "Ctrl Alt D"
    some tips:
            2011-8-21 17:01:35 com.tulskiy.keymaster.osx.CarbonProvider$1 run
            信息: Starting OSX global hotkey provider
            2011-8-21 17:01:39 com.tulskiy.keymaster.osx.CarbonProvider resetAll
            信息: Resetting hotkeys
            2011-8-21 17:01:39 com.tulskiy.keymaster.osx.CarbonProvider register
            信息: Registered hotkey: ctrl alt pressed D
    when press down "Ctrl Alt D", have a error:
           2011-8-21 17:45:47 com.tulskiy.keymaster.osx.CarbonProvider$EventHandler callback
           信息: Received event id: 1
           Invalid memory access of location 0x7fff5f3f58d0 rip=0x7fff80bb2d07
    second:
    set a breakpoint on :   
           carbonProvider.java   
           185:    private class EventHandler implements Carbon.EventHandlerProcPtr {
           ……
           196:     return 0   
    Single-step debugging: and some Thread information as follows:
           CarbonProvider$EventHandler.callback(Pointer, Pointer, Pointer) 行: 196
           NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) 行: 不可用 [本机方法]
           NativeMethodAccessorImpl.invoke(Object, Object[]) 行: 39
           DelegatingMethodAccessorImpl.invoke(Object, Object[]) 行: 25
           Method.invoke(Object, Object...) 行: 597
           CallbackReference$DefaultCallbackProxy.invokeCallback(Object[]) 行: 394
           CallbackReference$DefaultCallbackProxy.callback(Object[]) 行: 424
    when the Thread go to
           CallbackReference$DefaultCallbackProxy.invokeCallback(Object[]) 行: 394
           CallbackReference$DefaultCallbackProxy.callback(Object[]) 行: 424
    then: when pass the                 CallbackReference$DefaultCallbackProxy.callback(Object[]) 行: 424
          the Thread go in the AWTAutoShutdown.notifyToolkitThreadFree() 行: 130 [没有局部变量可用]
    and Then will be error:       Invalid access of stack red zone 0x7fff5f400a40 rip=0x7fff80bb2d07

At the end : I will be continue debug it ;
I hope you can give some solutions . Thank you very much!

MediaKeys don't work on GNOME 3

I'm trying to use this to listen to media buttons on Fedora 21 (GNOME 3) and it never receives the event. GNOME pops up a circle with a slash through it for a second when I press those keys.

Exception re incorrect event thread when running with JavaFx

Hi there!
Thanks for the library.

Have been attempting to integrate with JavaFx. Specifically the version that ships with java 8.

It appears that between Swing and JavaFx, the method of running Runnable's on the event thread has changed.

From Provider.java, the line:
SwingUtilities.invokeLater(event);

Will create an exception in JavaFx which looks like this:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = AWT-EventQueue-0

However updating the line to this:
javafx.application.Platform.runLater(event);

....works for the version of JavaFx I've been using.

I found some info about it here on stackoverflow

If you wanted to integrate with JavaFx, I'm not sure what the best method interface would be. Maybe a new getCurrentProvider() method which takes an enum. e.g.
Provider provider = Provider.getCurrentProvider(UseApplicationThread.JAVA_FX);

id comming in lParam ( win 7 x64 )

WindowsProvider is looking for the hotKey id in wParam, but I am seeing it in lParam. I have registered more than 1 hotkey and the provider is always returning the first hotkey in the hotKeys list.

I have not tested on 32 bit windows yet.

Unable to read "control alt RIGHT" or "alt TAB" keystrokes under Ubuntu 11.10 (32-bit processor)

I am working with scmurdock, and along with him, am very glad to have found your project. I have been able to successfully catch every keystroke using your program so far, but there is one that is still giving me difficulties: "control alt RIGHT".

Normally, when I make a registered keystroke while the program is running, the system gives me output showing that it recieved the event. For example:

Nov 11, 2011 3:18:35 PM com.tulskiy.keymaster.x11.X11Provider$1 run
INFO: Received event for hotkey: HotKey{ctrl alt T}
HotKey{ctrl alt T}

However, when I register the keystrokes, "control alt RIGHT" or "alt TAB", nothing is shown when I press them. It's as if the keystrokes weren't even seen by the program.

In my version of Ubuntu (11.10), the keystrokes "control alt RIGHT" and "alt TAB" by default are mapped as system shortcuts. I wonder if that has something to do with my problem. On the same note, I have been able to successfully receive other keystrokes which are by default mapped as system shortcuts (for example, "control alt T".)

Any help you could offer would be greatly appreciated.

NullPointerException at KeyMap.java:71 with JavaFX on Windows 10

If I start my JavaFX application this way:

public void start(Stage primaryStage) throws Exception{
  Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
  primaryStage.setTitle("Hello World");
  primaryStage.setScene(new Scene(root, 300, 275));
  primaryStage.show();

  Provider provider = Provider.getCurrentProvider(true);
  provider.register(KeyStroke.getKeyStroke("control shift b"), this::onHotkeyPressed);
}

public void onHotkeyPressed(HotKey hotKey){
  System.out.println(hotKey.toString());
}

...I get this error:

Apr. 08, 2020 11:44:33 AM com.tulskiy.keymaster.windows.WindowsProvider$1 run
INFO: Starting Windows global hotkey provider
Exception in thread "Thread-3" java.lang.NullPointerException
at com.tulskiy.keymaster.windows.KeyMap.getCode(KeyMap.java:71)
at com.tulskiy.keymaster.windows.WindowsProvider.register(WindowsProvider.java:101)
at com.tulskiy.keymaster.windows.WindowsProvider.access$700(WindowsProvider.java:39)
at com.tulskiy.keymaster.windows.WindowsProvider$1.run(WindowsProvider.java:82)
at java.base/java.lang.Thread.run(Thread.java:830)

Do I miss anything obvious?

Thanks

Reset or stop hangs the REPL (Clojure)

I don't know Java so I can't test in Java unfortunately, but when I try to issue .reset or .stop to the provider object in Clojure, the REPL hangs. If I do it in running code, the code continues (since it's multi-threaded), but the keys are not deregistered, and continue to be active...

    May 01, 2013 12:06:36 PM com.tulskiy.keymaster.osx.CarbonProvider$1 run
    INFO: Installing Event Handler
    May 01, 2013 12:06:36 PM com.tulskiy.keymaster.osx.CarbonProvider register
    INFO: Registered hotkey: shift ctrl pressed 1
    May 01, 2013 12:06:40 PM com.tulskiy.keymaster.osx.CarbonProvider$EventHandler callback
    INFO: Received event id: 1
    May 01, 2013 12:06:40 PM com.tulskiy.keymaster.osx.CarbonProvider stop
    INFO: Stopping now
    May 01, 2013 12:06:43 PM com.tulskiy.keymaster.osx.CarbonProvider$EventHandler callback
    INFO: Received event id: 1

JavaFX compatible version

Very useful library. Thanks for creating it.
Any chance of a JavaFX compatible version coming soon? i.e. using javafx.scene.input.KeyEvent instead of javax.swing.KeyStroke

PrintScreen (and SysRq) not being detected

I'm the author of Ginj, a screen capture application in Java, and I've selected JKeyMaster 1.3 for hotkey capture because it's easy to integrate and provides all the functionality I need. Thanks for the great project!

However, a user reported that the PrintScreen key isn't being captured.

I just tried JKeyMaster's AWTTest sample on my laptop (W10 64b, OpenJDK14) and indeed PrintScreen (obtained with FN key + Home) is not captured. Same for SysRq (FN + End). I was thinking the laptop's FN combination could be the culprit, but it doesn't seem so, as Pause (FN+PageUp) and Break (FN+PageDown) are detected correctly.
I noticed that even with AWTTest active, PrintScreen still triggers the default Windows behaviour (copy screen to clipboard), so I tried with modifiers. "Alt + PrintScreen" and "Win + PrintScreen" are natively captured by Windows, but "Ctrl + PrintScreen", "Shift + PrintScreen" and any combination of modifiers should be "free" but they all go unnoticed by JKeyMaster too.

What's weird is that there was a previous issue ( #9 ) about that specific key not working and it looks like it was fixed 8 years ago...

Is PrintScreen still supported in JKeyMaster 1.3 ? Is there something special I should do to enable that key ?

Linux xcb problems

Well I guess it wasn't solved, key binding works however this problem still occurs.

The JVM outputs this:

[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
java: ../../src/xcb_io.c:273: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted

Was tested on Ubuntu 11.10 x86_64 again...
Stops the whole program after a random key press (a hotkey of course, just it doesn't happen every time)

Hopefully this is a bit more clear than my other issue :p

Swing crashes when having bad native link

Hi,

I am using jKeyMaster in my project ScreenStudio (screenstudio.crombz.com). The library does work well. But I am facing one issue where I'm trying to catch the exception is some libraries are missing.

Basically, I have this case:

  • jna.jar is available
  • Ubuntu 14.04 libjna-java is installed

Using a "third-party" jna.jar instead of the native one, there is an issue between jna.jar and the libjna-java libraries. This is a case that can happen when people are not installer the proper dependencies.

What I am trying to do is to catch the error to be able to tell the user that the current setup is not working as expected and "Hot keys" won't work.

This is the exception from the console...
15-Aug-2014 10:30:46 AM com.tulskiy.keymaster.x11.X11Provider$1 run
INFO: Starting X11 global hotkey provider
Exception in thread "Thread-1" java.lang.UnsatisfiedLinkError: Can't obtain updateLastError method for class com.sun.jna.Native
at com.sun.jna.Native.initIDs(Native Method)
at com.sun.jna.Native.(Native.java:139)
at com.tulskiy.keymaster.x11.X11.(X11.java:31)
at com.tulskiy.keymaster.x11.X11Provider$1.run(X11Provider.java:54)
at java.lang.Thread.run(Thread.java:701)

The problem is that I cannot catch the exception, coming from a thread and basically, the Swing GUI does not show making impossible showing an error message to the user.

I am using jKeymaster 1.1 binary build.

Possible solutions: Have an event "OnError" or throw an exception on the ".reset" or the ".register".

I will try to find a work-around but it would be nice if the exception would not freeze the main program.

Thanks!

Snapshot not running due to NoClassDefFoundError

When building jar like written in readme and trying to run it afterwards I get a NoClassDefFoundError for "com/sun/jna/Platform". I am running Oracle JDK 8 under Ubuntu 14.04 - can you imagine what the reason for this error is and what the solution could look like?

error on Win10/x86_64/jdk8/jna 5.2.0

Getting the following error when trying to set up the provider as described in the README:

17:33:58 [Thread-1] INFO WindowsProvider - Starting Windows global hotkey provider
Exception in thread "Thread-1" java.lang.IllegalArgumentException: Invalid Structure field in class com.tulskiy.keymaster.windows.User32$MSG, field name 'wParam' (class com.tulskiy.keymaster.windows.User32$Parameter): The type "com.tulskiy.keymaster.windows.User32$Parameter" is not supported: Can't create an instance of class com.tulskiy.keymaster.windows.User32$Parameter, requires a public no-arg constructor: java.lang.reflect.InvocationTargetException
at com.sun.jna.Structure.validateField(Structure.java:1214)
at com.sun.jna.Structure.validateFields(Structure.java:1223)
at com.sun.jna.Structure.(Structure.java:200)
at com.sun.jna.Structure.(Structure.java:193)
at com.sun.jna.Structure.(Structure.java:180)
at com.sun.jna.Structure.(Structure.java:172)
at com.tulskiy.keymaster.windows.User32$MSG.(User32.java:54)
at com.tulskiy.keymaster.windows.WindowsProvider$1.run(WindowsProvider.java:55)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: The type "com.tulskiy.keymaster.windows.User32$Parameter" is not supported: Can't create an instance of class com.tulskiy.keymaster.windows.User32$Parameter, requires a public no-arg constructor: java.lang.reflect.InvocationTargetException
at com.sun.jna.Native.getNativeSize(Native.java:1356)
at com.sun.jna.Structure.getNativeSize(Structure.java:2172)
at com.sun.jna.Structure.getNativeSize(Structure.java:2162)
at com.sun.jna.Structure.validateField(Structure.java:1210)
... 8 more

register() not always fully activated in macOS

This is a weird one, but on macOS if you try to use jkeymaster on a plain CLI application registering hotkeys will usually not work. The reason seems to be that hotkeys aren't registered until you get a java Application (not a plain process) running. By that I mean a "java" Application that is showing in the Dock.

The workaround I managed to find is to call Toolkit.getDefaultToolkit() before I register any hotkeys. This starts up a proper java macOS Application, and after that everything works as expected.

I don't know if there's a better way to handle this. But whatever the solution is, I think adding it to jkeymaster would make sense because I would imagine it would trip up a lot of people (assuming you're not using AWT/Swing... since in that case you would already have an Application started).

I hope my description made sense. It might be a little confusing.

Clojure example

I'm just leaving it here because it might be useful to others, here's a minimal (and ugly, but functional) example using jkeymaster from Clojure:

add this to project.clj

:dependencies [[com.github.tulskiy/jkeymaster "1.1"]]

And this is the main code:

(ns keys.core
  (:gen-class)
  (:use (com.tulskiy.keymaster.common)))

(defn register []
  (let [provider (com.tulskiy.keymaster.common.Provider/getCurrentProvider true)
        listener (proxy [com.tulskiy.keymaster.common.HotKeyListener] [] (onHotKey [hotKey] (println hotKey)))
        keystroke (javax.swing.KeyStroke/getKeyStroke "control shift 1")]
    (.init provider)
    (.register provider keystroke listener)))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (register))

I'll keep playing with this and maybe even write a tiny wrapper library for Clojure (which I'm just learning).

Logging Abstraction

Hey,
I am interested in using this library for my project, however I would like to have to logging also looped through my logging system of choice automatically using slf4j.

If I'd make you a pull request where I replace all the JUL stuff with slf4j, would you be willing to merge it?

alt ctrl Windows keys on Win 7 not working

I assume I'm doing something wrong but when I run the test it works with simple keys but not these key combinations. Shift does seem to work. For instance I capture 'ctrl T' which reports that it is registered but doesn't seem to capture. Here is the log:

Dec 9, 2011 8:49:34 AM com.tulskiy.keymaster.windows.WindowsProvider register
INFO: Registering hotkey: HotKey{shift T}
Dec 9, 2011 8:49:44 AM com.tulskiy.keymaster.windows.WindowsProvider$1 run
INFO: Reset hotkeys
Dec 9, 2011 8:49:44 AM com.tulskiy.keymaster.windows.WindowsProvider register
INFO: Registering hotkey: HotKey{ctrl T}

Build failure

When I try to build (Windows 10 64-bit) using Maven I get a build error.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.5:sign (sign-artifacts) on project jkeymaster-parent: Exit code: 1 -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.5:sign (sign-artifacts) on project jkeymaster-parent: Exit code: 1 at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288) at org.apache.maven.cli.MavenCli.main (MavenCli.java:192) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) Caused by: org.apache.maven.plugin.MojoExecutionException: Exit code: 1 at org.apache.maven.plugin.gpg.GpgSigner.generateSignatureForFile (GpgSigner.java:168) at org.apache.maven.plugin.gpg.AbstractGpgSigner.generateSignatureForArtifact (AbstractGpgSigner.java:205) at org.apache.maven.plugin.gpg.GpgSignAttachedMojo.execute (GpgSignAttachedMojo.java:176) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288) at org.apache.maven.cli.MavenCli.main (MavenCli.java:192) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) [ERROR]

Joysticks

Hello,

I've been using your code in my project OSplt. It works wonderfully and I'm very greatful. I was wondering if there was some way to deal with Joystick input, as it would be quite useful for my project.

Shortcuts do not register on Windows 8 or Kali Linux

Great library. Works perfect on my Mac OSX and Windows 7. Unfortunately it does not register on my Windows 8 32-bit, or Kali Linux.

Linux error is as follows:

INFO: Starting X11 global hotkey provider
Exception in thread "Thread-3" java.lang.UnsatisfiedLinkError: Can't obtain updateLastError method for class com.sun.jna.Native
at com.sun.jna.Native.initIDs(Native Method)
at com.sun.jna.Native.(Native.java:139)
at com.tulskiy.keymaster.x11.X11.(X11.java:31)
at com.tulskiy.keymaster.x11.X11Provider$1.run(X11Provider.java:54)
at java.lang.Thread.run(Thread.java:745)

X11Provider.java fails on Ubuntu 11.10

Hello- I've been working with your package and am very happy to find it. I previously worked with another package that relies heavily on JNI. Running your example code ProviderTest.java produces the following stack trace:

Nov 10, 2011 6:48:03 AM com.tulskiy.keymaster.x11.X11Provider$1 run
INFO: Starting X11 global hotkey provider
Exception in thread "Thread-1" java.lang.UnsatisfiedLinkError: Unable to load library 'X11': com.sun.jna.Native.open(Ljava/lang/String;)J
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:166)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:239)
at com.sun.jna.Library$Handler.(Library.java:140)
at com.sun.jna.Native.loadLibrary(Native.java:393)
at com.sun.jna.Native.loadLibrary(Native.java:378)
at com.tulskiy.keymaster.x11.X11.(X11.java:29)
at com.tulskiy.keymaster.x11.X11Provider$1.run(X11Provider.java:56)
at java.lang.Thread.run(Thread.java:679)

I noticed you posted a similar error on the JNA project site. I don't seem to be able to fix it using your fix mentioned:

java-native-access/jna#12

Perhaps I'm not putting the line of code in the right place or perhaps I don't have a symlink where it ought to be, but here's the code I added:

X11Provider.java

public void init() {
    Runnable runnable = new Runnable() {
        public void run() {
            logger.info("Starting X11 global hotkey provider");
            System.setProperty("java.library.path", "/usr/lib/");//added per https://github.com/twall/jna/issues/12 [sean] 11-10-11
            display = Lib.XOpenDisplay(null);

It still fails. I'm not too familiar with JNA, but would really love to get this to work on Ubuntu 11.10 :)

Any help is greatly appreciated.

Thanks!

Sean

BadAccess - Ubuntu and ArchLinux

I'm working on a small screenshot program for Windows and Linux (possibly mac) and I have a few people testing that report "Bad Access" problems, is there anything that could fix it that I am missing? Or is it a problem related to their privileges?

Jan 11, 2012 11:13:56 PM com.tulskiy.keymaster.x11.X11Provider$ErrorHandler apply
WARNING: Error: BadAccess (attempt to access private resource denied)

Though it does work, after attempting to use the key it will read it once then say "[xcb] Unknown sequence number while processing queue"

Everything so far works great on Windows, far better than the 2 other libraries I was using (JXGrabKey and JIntellitype), and even in testing the Ubuntu VMWare instance I was running ran it fine, but if you could maybe shed some light on this problem it would be appreciated

Also, I suggest adding Printscreen keys, I had to hunt around for their ids and guess at a few (Windows was easy), if you want the Windows and Linux ones are... 0x2C and 0xff61

A little update:
Attempting to use either your file to test or my whole program on Ubuntu 11.10 causes this problem

How can I pass fired keyboard events to other applications without completely consuming it?

I am struggling to implement 'enable/disable' hotkeys features in my hotkey application.
So far I'm trying to achieve is rely on an 'disabled' flag and achieve something like:

OnHotKey:
if(disabled){
pass this key to the rest of the apps;
do nothing and return;
}

Or else can I can have my own implementation something like:

provider.pause();
provider.resume();

Would love to submit a PR, can you guide me a little as in what classes/methods to play around to implement this feature ?

Error in API example

In the API example in the README, it says to start a new connection with

Provider provider = Provider.getCurrentProvider();

however, according to the source code, this function requires a boolean parameter.

Hotkey events don't return to system (Windows)

Hotkey events captured by this code are not returned to system. This causes two drawbacks for me:

  1. Same hotkeys used in other aplications running on OS are not working. For example when I register "Ctrl + Tab" hotkey in my appliacation, this shortcut won't work for Internet browsers anymore, where it normally switch to next tab.
  2. I can't use released hotkeys alongside with pressed (default) ones. For example when I implement:
    provider.register(KeyStroke.getKeyStroke("control PERIOD"), listener); provider.register(KeyStroke.getKeyStroke("control released PERIOD"), listener2);
    or by other way to do this
    provider.register(KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, InputEvent.CTRL_MASK), listener); provider.register(KeyStroke.getKeyStroke(KeyEvent.VK_PERIOD, InputEvent.CTRL_MASK, true), listener2);
    only pressed event will occur, released will never happen. (becouse pressed event was "consumed"/not returned to OS) When I register only second (released) hotkey, without first one (pressed), it works fine, but usually you want to use released hotkey alongside with pressed. (when you want something to keep happening for period of time between pressing and releasing keyboard key) Unfortunately I can't implement something like this with this code.

I analized your code and I thought that code causing this behaviour is line 58 in class WindowsProvider (I'm using Windows OS):
while (PeekMessage(msg, null, 0, 0, PM_REMOVE)) {
According to PeekMessage function description, PM_REMOVE value (0x0001) removes message from the queue, while PM_NOREMOVE (0x0000) don't. So I tried to use PM_NOREMOVE value there, but this causes message to be processed by this code in endless loop. But even if I change while to if, this didn't cause same shortcut in other application to work... so I guess either it's not what I'm looking for, or I did something wrong. (probably second one, as other shortcuts in my application after using first one also don't work - as loop is processing first one all the time) Or maybe I just have to manually remove message from the queue and it has nothing to do with other applications? Anyway I have no success with trying to implement PM_NOREMOVE value. I also tried to use GetMessage instead of PeekMessage, but it works differently and I didn't manage to implement similar behaviour to your code.

I'm not asking to enable returning hotkey events to system, as it looks like a lot of work, but maybe you could at least give me some pointers or ideas about how could I implement this to work?

Thank you in advance for your help.

Отлов PREENTSCREEN не работает

В Ubuntu 11.10 у меня такая же проблема.

Provider provider = X11Provider.getCurrentProvider(false);
provider.register(KeyStroke.getKeyStroke("shift PRINTSCREEN"), new HotKeyListener() {
...
}

Вероятно, что на mac ox тоже она проявляется.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.