aboutsummaryrefslogtreecommitdiffstats
path: root/src/ru/olamedia/input
diff options
context:
space:
mode:
authorolamedia <[email protected]>2012-12-23 11:30:36 +0600
committerolamedia <[email protected]>2012-12-23 11:30:36 +0600
commitf58bdfcb66353bb77213cab580bc49ef890417ad (patch)
tree2983a05d564891e92c115a679f9bfbf55465c755 /src/ru/olamedia/input
parent5320fd1dad5b77fa227e83fbbe0a958f2c5fc283 (diff)
0.1.7
Diffstat (limited to 'src/ru/olamedia/input')
-rw-r--r--src/ru/olamedia/input/Keyboard.java77
-rw-r--r--src/ru/olamedia/input/MouseJail.java44
-rw-r--r--src/ru/olamedia/input/MouseListener.java4
3 files changed, 97 insertions, 28 deletions
diff --git a/src/ru/olamedia/input/Keyboard.java b/src/ru/olamedia/input/Keyboard.java
index 6a9ecbd..77e0b7a 100644
--- a/src/ru/olamedia/input/Keyboard.java
+++ b/src/ru/olamedia/input/Keyboard.java
@@ -36,22 +36,79 @@ public class Keyboard implements com.jogamp.newt.event.KeyListener {
@Override
public void keyPressed(com.jogamp.newt.event.KeyEvent e) {
- downState[e.getKeyCode()] = true;
- if (names.containsValue(e.getKeyCode())) {
- String name = (String) names.getKey(e.getKeyCode());
- for (ru.olamedia.input.KeyListener l : listeners) {
- l.onKeyPressed(name, e);
+ /*
+ * Key pressed: 87
+ * Key pressed: 65
+ * Key pressed: 83
+ * Key pressed: 68
+ * Key pressed: 65034
+ * Key pressed: 1731
+ * Key pressed: 1734
+ * Key pressed: 1753
+ * Key pressed: 1751
+ *
+ * keycode 24 = q Q Cyrillic_shorti Cyrillic_SHORTI
+ * keycode 25 = w W Cyrillic_tse Cyrillic_TSE
+ * keycode 26 = e E Cyrillic_u Cyrillic_U
+ * keycode 27 = r R Cyrillic_ka Cyrillic_KA
+ * keycode 28 = t T Cyrillic_ie Cyrillic_IE
+ * keycode 29 = y Y Cyrillic_en Cyrillic_EN
+ * keycode 30 = u U Cyrillic_ghe Cyrillic_GHE
+ * keycode 31 = i I Cyrillic_sha Cyrillic_SHA
+ * keycode 32 = o O Cyrillic_shcha Cyrillic_SHCHA
+ * keycode 33 = p P Cyrillic_ze Cyrillic_ZE
+ *
+ * KeyPress event, serial 36, synthetic NO, window 0x4600001,
+ * root 0xb7, subw 0x0, time 326572351, (602,679), root:(669,730),
+ * state 0x10, keycode 25 (keysym 0x77, w), same_screen YES,
+ * XLookupString gives 1 bytes: (77) "w"
+ * XmbLookupString gives 1 bytes: (77) "w"
+ * XFilterEvent returns: False
+ *
+ * KeyRelease event, serial 36, synthetic NO, window 0x4600001,
+ * root 0xb7, subw 0x0, time 326572447, (602,679), root:(669,730),
+ * state 0x10, keycode 25 (keysym 0x77, w), same_screen YES,
+ * XLookupString gives 1 bytes: (77) "w"
+ * XFilterEvent returns: False
+ *
+ * KeyPress event, serial 36, synthetic NO, window 0x4600001,
+ * root 0xb7, subw 0x0, time 326588119, (118,-7), root:(185,44),
+ * state 0x2010, keycode 25 (keysym 0x6c3, Cyrillic_tse), same_screen
+ * YES,
+ * XLookupString gives 2 bytes: (d1 86) "ц"
+ * XmbLookupString gives 2 bytes: (d1 86) "ц"
+ * XFilterEvent returns: False
+ *
+ * KeyRelease event, serial 36, synthetic NO, window 0x4600001,
+ * root 0xb7, subw 0x0, time 326588200, (118,-7), root:(185,44),
+ * state 0x2010, keycode 25 (keysym 0x6c3, Cyrillic_tse), same_screen
+ * YES,
+ * XLookupString gives 2 bytes: (d1 86) "ц"
+ * XFilterEvent returns: False
+ */
+ if (e.getKeyCode() < 256) {
+ downState[e.getKeyCode()] = true;
+ if (names.containsValue(e.getKeyCode())) {
+ String name = (String) names.getKey(e.getKeyCode());
+ for (ru.olamedia.input.KeyListener l : listeners) {
+ l.onKeyPressed(name, e);
+ }
}
+ System.out.println("Key pressed: " + e.getKeyCode());
+ } else {
+ System.err.println("Key pressed: " + e.getKeyCode());
}
}
@Override
public void keyReleased(com.jogamp.newt.event.KeyEvent e) {
- downState[e.getKeyCode()] = false;
- if (names.containsValue(e.getKeyCode())) {
- String name = (String) names.getKey(e.getKeyCode());
- for (ru.olamedia.input.KeyListener l : listeners) {
- l.onKeyReleased(name, e);
+ if (e.getKeyCode() < 256) {
+ downState[e.getKeyCode()] = false;
+ if (names.containsValue(e.getKeyCode())) {
+ String name = (String) names.getKey(e.getKeyCode());
+ for (ru.olamedia.input.KeyListener l : listeners) {
+ l.onKeyReleased(name, e);
+ }
}
}
}
diff --git a/src/ru/olamedia/input/MouseJail.java b/src/ru/olamedia/input/MouseJail.java
index bd12b0a..9168cc8 100644
--- a/src/ru/olamedia/input/MouseJail.java
+++ b/src/ru/olamedia/input/MouseJail.java
@@ -1,9 +1,5 @@
package ru.olamedia.input;
-import java.awt.AWTException;
-import java.awt.Point;
-import java.awt.Robot;
-import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@@ -15,10 +11,22 @@ import ru.olamedia.game.GameFrame;
public class MouseJail extends MouseAdapter {
public static MouseJail instance = new MouseJail();
+ public int x;
+ public int y;
+
public MouseJail() {
}
private static boolean isActive = false;
+ private static boolean isEnabled = true; // disabled if GUI is opened
+
+ public static void disable() {
+ isEnabled = false;
+ }
+
+ public static void enable() {
+ isEnabled = true;
+ }
/**
* @return the isActive
@@ -32,22 +40,26 @@ public class MouseJail extends MouseAdapter {
* the isActive to set
*/
public static void setActive(boolean isActive) {
- System.out.println("Mouse jail " + (isActive ? "active" : "not active"));
- MouseJail.isActive = isActive;
- GameFrame.confinePointer(isActive);
- GameFrame.setPointerVisible(!isActive);
+ if (isEnabled) {
+ System.out.println("Mouse jail " + (isActive ? "active" : "not active"));
+ MouseJail.isActive = isActive;
+ GameFrame.confinePointer(isActive);
+ GameFrame.setPointerVisible(!isActive);
+ }
}
@Override
public void mouseClicked(MouseEvent e) {
+ // if (isEnabled) {
if (e.isAltDown()) {
setActive(false);
} else {
setActive(true);
}
for (ru.olamedia.input.MouseListener l : listeners) {
- l.onMouseClick();
+ l.onMouseClick(e);
}
+ // }
}
@Override
@@ -61,7 +73,7 @@ public class MouseJail extends MouseAdapter {
System.out.println("Exited");
isActive = false;
if (isActive) {
- //moveToCenter();
+ // moveToCenter();
}
}
@@ -83,19 +95,17 @@ public class MouseJail extends MouseAdapter {
private float sensitivity = 2f;
private void onMove(MouseEvent e) {
+ x = e.getX();
+ y = e.getY();
if (isActive) {
- int cx = GameFrame.getWidth() / 2;
- int cy = GameFrame.getHeight() / 2;
- float dx = e.getX() - cx;
- float dy = e.getY() - cy;
- dx *= sensitivity / 10;
- dy *= sensitivity / 10;
+ final float dx = (e.getX() - GameFrame.getGLWidth() / 2) * sensitivity / 10;
+ final float dy = (e.getY() - GameFrame.getGLHeight() / 2) * sensitivity / 10;
// System.out.println("Mouse moved " + " dx:" + dx + " dy:" + dy
// + " x:" + e.getX() + " y:" + e.getY());
for (ru.olamedia.input.MouseListener l : listeners) {
l.onMouseMove(dx, dy);
}
- GameFrame.getWindow().warpPointer(cx, cy);
+ GameFrame.getWindow().warpPointer(GameFrame.getGLWidth() / 2, GameFrame.getGLHeight() / 2);
}
}
diff --git a/src/ru/olamedia/input/MouseListener.java b/src/ru/olamedia/input/MouseListener.java
index 3d93d1d..c9f7088 100644
--- a/src/ru/olamedia/input/MouseListener.java
+++ b/src/ru/olamedia/input/MouseListener.java
@@ -1,6 +1,8 @@
package ru.olamedia.input;
+import com.jogamp.newt.event.MouseEvent;
+
public interface MouseListener {
public void onMouseMove(float dx, float dy);
- public void onMouseClick();
+ public void onMouseClick(MouseEvent e);
}