回答編集履歴
2
見直しキャンペーン中
test
CHANGED
@@ -1,113 +1,57 @@
|
|
1
1
|
リンクのソースコードを見たところ、KeyPressedイベントで`e.KeyPressEvent.KeyPressState`が、
|
2
|
-
|
3
2
|
押したときとオートリピート中は `MAKE`
|
4
|
-
|
5
3
|
離したときは `BREAK`
|
6
4
|
|
7
|
-
|
8
|
-
|
9
5
|
MAKE
|
10
|
-
|
11
6
|
MAKE
|
12
|
-
|
13
7
|
MAKE
|
14
|
-
|
15
8
|
MAKE
|
16
|
-
|
17
9
|
BREAK
|
18
|
-
|
19
|
-
|
20
10
|
|
21
11
|
のように来るようです。これで判別できそうですね。
|
22
12
|
|
23
|
-
|
24
|
-
|
25
13
|
---
|
26
14
|
|
27
|
-
|
28
|
-
|
29
|
-
```
|
15
|
+
```cs
|
30
|
-
|
31
16
|
private bool p1_leftPressed;
|
32
|
-
|
33
17
|
private bool p1_rightPressed;
|
34
|
-
|
35
18
|
private bool p2_leftPressed;
|
36
|
-
|
37
19
|
private bool p2_rightPressed;
|
38
20
|
|
39
|
-
|
40
|
-
|
41
21
|
public void KeyPressed(object sender, RawInputEventArg e)
|
42
|
-
|
43
22
|
{
|
44
|
-
|
45
23
|
if(PlayersList1[e.KeyPressEvent.DeviceName] == 1)
|
46
|
-
|
47
24
|
{
|
48
|
-
|
49
25
|
switch(e.KeyPressEvent.VKeyName)
|
50
|
-
|
51
26
|
{
|
52
|
-
|
53
27
|
case "LEFT":
|
54
|
-
|
55
28
|
p1_leftPressed = e.KeyPressEvent.KeyPressState == "MAKE";
|
56
|
-
|
57
29
|
break;
|
58
|
-
|
59
30
|
case "RIGHT":
|
60
|
-
|
61
31
|
p1_rightPressed = e.KeyPressEvent.KeyPressState == "MAKE";
|
62
|
-
|
63
32
|
break;
|
64
|
-
|
65
33
|
}
|
66
|
-
|
34
|
+
}
|
35
|
+
else
|
36
|
+
{
|
37
|
+
switch(e.KeyPressEvent.VKeyName)
|
38
|
+
{
|
39
|
+
case "LEFT":
|
40
|
+
p2_leftPressed = e.KeyPressEvent.KeyPressState == "MAKE";
|
41
|
+
break;
|
42
|
+
case "RIGHT":
|
43
|
+
p2_rightPressed = e.KeyPressEvent.KeyPressState == "MAKE";
|
44
|
+
break;
|
45
|
+
}
|
67
46
|
}
|
68
47
|
|
69
|
-
else
|
70
|
-
|
71
|
-
{
|
72
|
-
|
73
|
-
switch(e.KeyPressEvent.VKeyName)
|
74
|
-
|
75
|
-
{
|
76
|
-
|
77
|
-
case "LEFT":
|
78
|
-
|
79
|
-
p2_leftPressed = e.KeyPressEvent.KeyPressState == "MAKE";
|
80
|
-
|
81
|
-
break;
|
82
|
-
|
83
|
-
case "RIGHT":
|
84
|
-
|
85
|
-
p2_rightPressed = e.KeyPressEvent.KeyPressState == "MAKE";
|
86
|
-
|
87
|
-
break;
|
88
|
-
|
89
|
-
}
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
|
95
48
|
// あくまでイメージです
|
96
|
-
|
97
49
|
if(p1_leftPressed) Player1.X -= 10;
|
98
|
-
|
99
50
|
if(p1_rightPressed) Player1.X += 10;
|
100
|
-
|
101
51
|
if(p2_leftPressed) Player2.X -= 10;
|
102
|
-
|
103
52
|
if(p2_rightPressed) Player2.X += 10;
|
104
|
-
|
105
53
|
}
|
106
|
-
|
107
54
|
```
|
108
55
|
|
109
|
-
|
110
|
-
|
111
56
|
こんな感じに(上下も作れば)同時押しも反応できますが、キーボードが2つあると一人が押したときと二人で同時に押したときでリピート速度が変わってしまうかもしれません。
|
112
|
-
|
113
57
|
その場合はタイマーで更新するしかないかもしれません。
|
1
イメージコード
test
CHANGED
@@ -19,3 +19,95 @@
|
|
19
19
|
|
20
20
|
|
21
21
|
のように来るようです。これで判別できそうですね。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
```C#
|
30
|
+
|
31
|
+
private bool p1_leftPressed;
|
32
|
+
|
33
|
+
private bool p1_rightPressed;
|
34
|
+
|
35
|
+
private bool p2_leftPressed;
|
36
|
+
|
37
|
+
private bool p2_rightPressed;
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
public void KeyPressed(object sender, RawInputEventArg e)
|
42
|
+
|
43
|
+
{
|
44
|
+
|
45
|
+
if(PlayersList1[e.KeyPressEvent.DeviceName] == 1)
|
46
|
+
|
47
|
+
{
|
48
|
+
|
49
|
+
switch(e.KeyPressEvent.VKeyName)
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
case "LEFT":
|
54
|
+
|
55
|
+
p1_leftPressed = e.KeyPressEvent.KeyPressState == "MAKE";
|
56
|
+
|
57
|
+
break;
|
58
|
+
|
59
|
+
case "RIGHT":
|
60
|
+
|
61
|
+
p1_rightPressed = e.KeyPressEvent.KeyPressState == "MAKE";
|
62
|
+
|
63
|
+
break;
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
else
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
switch(e.KeyPressEvent.VKeyName)
|
74
|
+
|
75
|
+
{
|
76
|
+
|
77
|
+
case "LEFT":
|
78
|
+
|
79
|
+
p2_leftPressed = e.KeyPressEvent.KeyPressState == "MAKE";
|
80
|
+
|
81
|
+
break;
|
82
|
+
|
83
|
+
case "RIGHT":
|
84
|
+
|
85
|
+
p2_rightPressed = e.KeyPressEvent.KeyPressState == "MAKE";
|
86
|
+
|
87
|
+
break;
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
// あくまでイメージです
|
96
|
+
|
97
|
+
if(p1_leftPressed) Player1.X -= 10;
|
98
|
+
|
99
|
+
if(p1_rightPressed) Player1.X += 10;
|
100
|
+
|
101
|
+
if(p2_leftPressed) Player2.X -= 10;
|
102
|
+
|
103
|
+
if(p2_rightPressed) Player2.X += 10;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
こんな感じに(上下も作れば)同時押しも反応できますが、キーボードが2つあると一人が押したときと二人で同時に押したときでリピート速度が変わってしまうかもしれません。
|
112
|
+
|
113
|
+
その場合はタイマーで更新するしかないかもしれません。
|