-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionToKey.java
More file actions
96 lines (90 loc) · 2.61 KB
/
FunctionToKey.java
File metadata and controls
96 lines (90 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package awpsoft.gamemodule;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
public class FunctionToKey implements KeyListener
{
public int[] KeysOfFunction;
private boolean[] KeyState;
//A Function Has Four Virtual Keys, Use >>> And &0xFF Get,Use << And | Set
public FunctionToKey()
{
KeysOfFunction = new int[0x100];
KeyState = new boolean[0x100];
}
//Your Set At This
public void setKeysOfFunction(int functionIndex, int key1, int key2, int key3, int key4)
{
if (functionIndex < 0x0 || functionIndex >= 0x100) return;
int temp = key4 & 0x000000ff;
temp <<= 8;
temp |= key3 & 0x000000ff;
temp <<= 8;
temp |= key2 & 0x000000ff;
temp <<= 8;
temp |= key1 & 0x000000ff;
KeysOfFunction[functionIndex] = temp;
}
public void setKeysOfFunction(int functionIndex, int key1, int key2, int key3)
{
if (functionIndex < 0x0 || functionIndex >= 0x100) return;
int temp = 0;
temp |= key3 & 0x000000ff;
temp <<= 8;
temp |= key2 & 0x000000ff;
temp <<= 8;
temp |= key1 & 0x000000ff;
KeysOfFunction[functionIndex] = temp;
}
public void setKeysOfFunction(int functionIndex, int key1, int key2)
{
if (functionIndex < 0x0 || functionIndex >= 0x100) return;
int temp = 0;
temp |= key2 & 0x000000ff;
temp <<= 8;
temp |= key1 & 0x000000ff;
KeysOfFunction[functionIndex] = temp;
}
public void setKeysOfFunction(int functionIndex, int key1)
{
if (functionIndex < 0x0 || functionIndex >= 0x100) return;
KeysOfFunction[functionIndex] = key1 & 0x000000ff;
}
int getKeysOfFunction(int functionIndex)
{
if (functionIndex < 0x0 || functionIndex >= 0x100)
{
return 0x0;
}
return KeysOfFunction[functionIndex];
}
boolean getFunctionState(int functionIndex)
{
if (functionIndex < 0x0 || functionIndex >= 0x100)
{
return false;
}
int temp = KeysOfFunction[functionIndex];
if ((temp & 0xFF) != 0 && KeyState[temp & 0xFF]) return true;
temp >>>= 8;
if ((temp & 0xFF) != 0 && KeyState[temp & 0xFF]) return true;
temp >>>= 8;
if ((temp & 0xFF) != 0 && KeyState[temp & 0xFF]) return true;
temp >>>= 8;
if ((temp & 0xFF) != 0 && KeyState[temp & 0xFF]) return true;
return false;
}
@Override
public void keyTyped(KeyEvent e) {}
@Override
public void keyPressed(KeyEvent e)
{
int code = e.getKeyCode();
if(code >=0 && code <0x100) KeyState[code] = true;
}
@Override
public void keyReleased(KeyEvent e)
{
int code = e.getKeyCode();
if(code >=0 && code < 0x100) KeyState[code] = false;
}
}