-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
851 additions
and
673 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
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
62 changes: 25 additions & 37 deletions
62
app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeysInterceptor.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,49 +1,37 @@ | ||
package com.mercury.platform.shared.hotkey; | ||
|
||
import org.jnativehook.GlobalScreen; | ||
import org.jnativehook.NativeHookException; | ||
|
||
import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; | ||
import com.mercury.platform.shared.store.MercuryStoreCore; | ||
import lc.kra.system.keyboard.GlobalKeyboardHook; | ||
import lc.kra.system.mouse.GlobalMouseHook; | ||
import lc.kra.system.mouse.event.GlobalMouseAdapter; | ||
import lc.kra.system.mouse.event.GlobalMouseEvent; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class HotKeysInterceptor { | ||
public HotKeysInterceptor() { | ||
GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook(false); | ||
keyboardHook.addKeyListener(new HotKeyAdapter()); | ||
Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName()); | ||
logger.setLevel(Level.OFF); | ||
|
||
GlobalMouseHook mouseHook = new GlobalMouseHook(false); | ||
mouseHook.addMouseListener(new GlobalMouseAdapter() { | ||
@Override | ||
public void mousePressed(GlobalMouseEvent globalMouseEvent) { | ||
MercuryStoreCore.hotKeySubject.onNext(this.convert(globalMouseEvent)); | ||
} | ||
private HotKeyDescriptor convert(GlobalMouseEvent event) { | ||
HotKeyDescriptor descriptor = new HotKeyDescriptor(); | ||
switch (event.getButton()){ | ||
case 1: { | ||
descriptor.setVirtualKeyCode(1000); | ||
descriptor.setTitle("Mouse left"); | ||
break; | ||
} | ||
case 2: { | ||
descriptor.setVirtualKeyCode(1002); | ||
descriptor.setTitle("Mouse right"); | ||
break; | ||
} | ||
case 16: { | ||
descriptor.setVirtualKeyCode(1016); | ||
descriptor.setTitle("Mouse middle"); | ||
break; | ||
} | ||
} | ||
return descriptor; | ||
} | ||
}); | ||
logger.setUseParentHandlers(false); | ||
try { | ||
GlobalScreen.registerNativeHook(); | ||
} catch (NativeHookException e) { | ||
e.printStackTrace(); | ||
} | ||
GlobalScreen.addNativeKeyListener(new MercuryNativeKeyListener()); | ||
GlobalScreen.addNativeMouseListener(new MercuryNativeMouseListener()); | ||
} | ||
|
||
public static void main(String[] args) { | ||
new HotKeysInterceptor(); | ||
// new HotKeysInterceptor(); | ||
Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName()); | ||
logger.setLevel(Level.OFF); | ||
|
||
logger.setUseParentHandlers(false); | ||
try { | ||
GlobalScreen.registerNativeHook(); | ||
} catch (NativeHookException e) { | ||
e.printStackTrace(); | ||
} | ||
GlobalScreen.addNativeMouseListener(new MercuryNativeMouseListener()); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.mercury.platform.shared.hotkey; | ||
|
||
|
||
import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; | ||
import com.mercury.platform.shared.store.MercuryStoreCore; | ||
import org.jnativehook.keyboard.NativeKeyEvent; | ||
import org.jnativehook.keyboard.NativeKeyListener; | ||
|
||
public class MercuryNativeKeyListener implements NativeKeyListener{ | ||
private boolean menuPressed; | ||
private boolean shiftPressed; | ||
private boolean ctrlpressed; | ||
@Override | ||
public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) { | ||
switch (nativeKeyEvent.getKeyCode()){ | ||
case 42 : { | ||
this.shiftPressed = true; | ||
break; | ||
} | ||
case 29: { | ||
this.ctrlpressed = true; | ||
break; | ||
} | ||
case 56: { | ||
this.menuPressed = true; | ||
break; | ||
} | ||
default:{ | ||
HotKeyDescriptor hotKeyDescriptor = new HotKeyDescriptor(); | ||
hotKeyDescriptor.setTitle(NativeKeyEvent.getKeyText(nativeKeyEvent.getKeyCode())); | ||
hotKeyDescriptor.setVirtualKeyCode(nativeKeyEvent.getKeyCode()); | ||
hotKeyDescriptor.setControlPressed(this.ctrlpressed); | ||
hotKeyDescriptor.setShiftPressed(this.shiftPressed); | ||
hotKeyDescriptor.setMenuPressed(this.menuPressed); | ||
|
||
hotKeyDescriptor.setTitle(this.getButtonText(hotKeyDescriptor)); | ||
MercuryStoreCore.hotKeySubject.onNext(hotKeyDescriptor); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) { | ||
switch (nativeKeyEvent.getKeyCode()){ | ||
case 42 : { | ||
this.shiftPressed = false; | ||
break; | ||
} | ||
case 29: { | ||
this.ctrlpressed = false; | ||
break; | ||
} | ||
case 56: { | ||
this.menuPressed = false; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent) { | ||
|
||
} | ||
private String getButtonText(HotKeyDescriptor descriptor){ | ||
String text = descriptor.getTitle(); | ||
if(descriptor.isShiftPressed()) | ||
text = "Shift + " + text; | ||
if(descriptor.isMenuPressed()) | ||
text = "Alt + " + text; | ||
if(descriptor.isControlPressed()) | ||
text = "Ctrl + " + text; | ||
return text; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeMouseListener.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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.mercury.platform.shared.hotkey; | ||
|
||
import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; | ||
import com.mercury.platform.shared.store.MercuryStoreCore; | ||
import org.jnativehook.mouse.NativeMouseEvent; | ||
import org.jnativehook.mouse.NativeMouseListener; | ||
|
||
public class MercuryNativeMouseListener implements NativeMouseListener { | ||
@Override | ||
public void nativeMouseClicked(NativeMouseEvent nativeMouseEvent) { | ||
} | ||
|
||
@Override | ||
public void nativeMousePressed(NativeMouseEvent nativeMouseEvent) { | ||
HotKeyDescriptor hotKeyDescriptor = new HotKeyDescriptor(); | ||
hotKeyDescriptor.setVirtualKeyCode(nativeMouseEvent.getButton() + 10000); | ||
hotKeyDescriptor.setTitle(this.getModifiersText(nativeMouseEvent.getButton())); | ||
MercuryStoreCore.hotKeySubject.onNext(hotKeyDescriptor); | ||
} | ||
|
||
@Override | ||
public void nativeMouseReleased(NativeMouseEvent nativeMouseEvent) { | ||
} | ||
|
||
private String getModifiersText(int code) { | ||
switch (code) { | ||
case 1: { | ||
return "Mouse left"; | ||
} | ||
case 2: { | ||
return "Mouse right"; | ||
} | ||
case 3: { | ||
return "Mouse middle"; | ||
} | ||
case 4: { | ||
return "Button 4"; | ||
} | ||
case 5: { | ||
return "Button 5"; | ||
} | ||
case 6: { | ||
return "Button 6"; | ||
} | ||
case 7: { | ||
return "Button 7"; | ||
} | ||
default: { | ||
return "Undefined"; | ||
} | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app-core/src/test/java/com/mercury/platform/shared/MainTestKeyHook.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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.mercury.platform.shared; | ||
|
||
import com.sun.jna.platform.win32.Kernel32; | ||
import com.sun.jna.platform.win32.User32; | ||
import com.sun.jna.platform.win32.WinDef.HINSTANCE; | ||
import com.sun.jna.platform.win32.WinDef.LPARAM; | ||
import com.sun.jna.platform.win32.WinDef.LRESULT; | ||
import com.sun.jna.platform.win32.WinDef.WPARAM; | ||
import com.sun.jna.platform.win32.WinUser.HOOKPROC; | ||
|
||
public class MainTestKeyHook { | ||
|
||
|
||
public static void main(String[] args) throws Exception { | ||
HOOKPROC hookProc = new HOOKPROC_bg(); | ||
HINSTANCE hInst = Kernel32.INSTANCE.GetModuleHandle(null); | ||
|
||
User32.HHOOK hHook = User32.INSTANCE.SetWindowsHookEx(User32.WH_KEYBOARD_LL, hookProc, hInst, 0); | ||
if (hHook == null) | ||
return; | ||
User32.MSG msg = new User32.MSG(); | ||
System.err.println("Please press any key ...."); | ||
while (true) { | ||
User32.INSTANCE.GetMessage(msg, null, 0, 0); | ||
} | ||
} | ||
} | ||
|
||
class HOOKPROC_bg implements HOOKPROC { | ||
|
||
public HOOKPROC_bg() { | ||
} | ||
|
||
public LRESULT callback(int nCode, WPARAM wParam, LPARAM lParam) { | ||
System.err.println("callback bbbnhkilhjkibh nCode: " + nCode); | ||
return new LRESULT(0); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
...i/src/main/java/com/mercury/platform/ui/components/panel/message/HistoryMessagePanel.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mercury.platform.ui.components.panel.message; | ||
|
||
/** | ||
* Created by Константин on 10.08.2017. | ||
*/ | ||
public class HistoryMessagePanel { | ||
} |
Oops, something went wrong.