-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 3.0, added raw input support, merged native libraries, added
functions to list connected keyboards / mice, see #12, fixed some bugs
- Loading branch information
Showing
17 changed files
with
861 additions
and
746 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version: 2.6.{build} | ||
version: 3.0.{build} | ||
|
||
branches: | ||
only: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 54 additions & 49 deletions
103
src/main/java/lc/kra/system/keyboard/example/GlobalKeyboardExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,55 @@ | ||
/** | ||
* Copyright (c) 2016 Kristian Kraljic | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package lc.kra.system.keyboard.example; | ||
|
||
import lc.kra.system.keyboard.GlobalKeyboardHook; | ||
import lc.kra.system.keyboard.event.GlobalKeyAdapter; | ||
import lc.kra.system.keyboard.event.GlobalKeyEvent; | ||
|
||
public class GlobalKeyboardExample { | ||
private static boolean run = true; | ||
public static void main(String[] args) { | ||
// might throw a UnsatisfiedLinkError if the native library fails to load or a RuntimeException if hooking fails | ||
GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook(); | ||
|
||
System.out.println("Global keyboard hook successfully started, press [escape] key to shutdown."); | ||
keyboardHook.addKeyListener(new GlobalKeyAdapter() { | ||
@Override public void keyPressed(GlobalKeyEvent event) { | ||
System.out.println(event); | ||
if(event.getVirtualKeyCode()==GlobalKeyEvent.VK_ESCAPE) | ||
run = false; | ||
} | ||
@Override public void keyReleased(GlobalKeyEvent event) { | ||
System.out.println(event); } | ||
}); | ||
|
||
try { | ||
while(run) Thread.sleep(128); | ||
} catch(InterruptedException e) { /* nothing to do here */ } | ||
finally { keyboardHook.shutdownHook(); } | ||
} | ||
/** | ||
* Copyright (c) 2016 Kristian Kraljic | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package lc.kra.system.keyboard.example; | ||
|
||
import java.util.Map.Entry; | ||
|
||
import lc.kra.system.keyboard.GlobalKeyboardHook; | ||
import lc.kra.system.keyboard.event.GlobalKeyAdapter; | ||
import lc.kra.system.keyboard.event.GlobalKeyEvent; | ||
|
||
public class GlobalKeyboardExample { | ||
private static boolean run = true; | ||
public static void main(String[] args) { | ||
// might throw a UnsatisfiedLinkError if the native library fails to load or a RuntimeException if hooking fails | ||
GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook(true); // use false here to switch to hook instead of raw input | ||
|
||
System.out.println("Global keyboard hook successfully started, press [escape] key to shutdown. Connected keyboards:"); | ||
for(Entry<Long,String> keyboard:GlobalKeyboardHook.listKeybords().entrySet()) | ||
System.out.format("%d: %s\n", keyboard.getKey(), keyboard.getValue()); | ||
|
||
keyboardHook.addKeyListener(new GlobalKeyAdapter() { | ||
@Override public void keyPressed(GlobalKeyEvent event) { | ||
System.out.println(event); | ||
if(event.getVirtualKeyCode()==GlobalKeyEvent.VK_ESCAPE) | ||
run = false; | ||
} | ||
@Override public void keyReleased(GlobalKeyEvent event) { | ||
System.out.println(event); } | ||
}); | ||
|
||
try { | ||
while(run) Thread.sleep(128); | ||
} catch(InterruptedException e) { /* nothing to do here */ } | ||
finally { keyboardHook.shutdownHook(); } | ||
} | ||
} |
Oops, something went wrong.