質問編集履歴
4
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -86,6 +86,45 @@
|
|
86
86
|
|
87
87
|
```
|
88
88
|
|
89
|
+
##### Input.hpp
|
90
|
+
```cpp
|
91
|
+
#ifndef ___IPNUT_HPP___
|
92
|
+
#define ___IPNUT_HPP___
|
93
|
+
|
94
|
+
#include "Data.hpp"
|
95
|
+
|
96
|
+
namespace Console
|
97
|
+
{
|
98
|
+
|
99
|
+
class Input
|
100
|
+
{
|
101
|
+
public:
|
102
|
+
static void InputKey();
|
103
|
+
|
104
|
+
static KeyCode GetKeyCode();
|
105
|
+
static KeyCode GetKeyDown();
|
106
|
+
static void ResetKey();
|
107
|
+
|
108
|
+
private:
|
109
|
+
|
110
|
+
static KeyCode keyInput;
|
111
|
+
static KeyCode prevKeyInput;
|
112
|
+
static bool flag;
|
113
|
+
Input();
|
114
|
+
~Input();
|
115
|
+
|
116
|
+
|
117
|
+
};
|
118
|
+
|
119
|
+
|
120
|
+
};
|
121
|
+
|
122
|
+
|
123
|
+
#endif
|
124
|
+
|
125
|
+
```
|
126
|
+
|
127
|
+
|
89
128
|
##### Input.cpp
|
90
129
|
```cpp
|
91
130
|
|
3
ソースコードを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,6 +27,47 @@
|
|
27
27
|
ああああ
|
28
28
|
```
|
29
29
|
##### Main.cpp
|
30
|
+
```cpp
|
31
|
+
#include <iostream>
|
32
|
+
#include "Screen.hpp"
|
33
|
+
#include <memory>
|
34
|
+
//#include <Magick++.h>
|
35
|
+
#include "../lib/src/Console.hpp"
|
36
|
+
|
37
|
+
|
38
|
+
int main()
|
39
|
+
{
|
40
|
+
Console::Init();
|
41
|
+
Console::Init_ErrorLog("log/error.log");
|
42
|
+
Console::Init_Log("log/log.log");
|
43
|
+
nodelay(stdscr,true);
|
44
|
+
Console::RenderBuffer(NULL);
|
45
|
+
|
46
|
+
|
47
|
+
std::unique_ptr<Screen> main = std::make_unique<Screen>();
|
48
|
+
|
49
|
+
while(true)
|
50
|
+
{
|
51
|
+
Console::ClearBuffer(stdscr);
|
52
|
+
|
53
|
+
main->Loop();
|
54
|
+
|
55
|
+
if (main->getExit() == true)
|
56
|
+
{
|
57
|
+
break;
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
Console::RenderBuffer(stdscr);
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
Console::Finalize();
|
66
|
+
|
67
|
+
return 0;
|
68
|
+
}
|
69
|
+
```
|
70
|
+
##### 利用部
|
30
71
|
```cpp
|
31
72
|
|
32
73
|
void Screen::Update()
|
@@ -93,7 +134,8 @@
|
|
93
134
|
if(keyInput != prevKeyInput)
|
94
135
|
{
|
95
136
|
flag = true;
|
96
|
-
}
|
137
|
+
}
|
138
|
+
|
97
139
|
}
|
98
140
|
else if(key == KEY_DOWN)
|
99
141
|
{
|
@@ -118,6 +160,18 @@
|
|
118
160
|
prevKeyInput = KeyCode::None;
|
119
161
|
}
|
120
162
|
|
163
|
+
|
164
|
+
|
165
|
+
|
121
166
|
prevKeyInput = keyInput;
|
122
167
|
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
void Console::Input::ResetKey()
|
173
|
+
{
|
174
|
+
//keyInput = KeyCode::None;
|
175
|
+
}
|
176
|
+
|
123
177
|
```
|
2
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
提示コードですが`else if(key == KEY_RIGHT)`つまり右キーを押した瞬間だけを取得したのですがbool型変数を使って判定処理を記述してもなぜか毎フレーム走ってしまいます。これはなぜでしょうか?
|
2
2
|
キー入力は押している間if文の中が実行されます。
|
3
|
+
|
4
|
+
##### 確認したいと
|
5
|
+
プロジェクト全体で別の場所で同じ関数が実行されていないあ確認
|
6
|
+
変数の型を確認
|
7
|
+
キーを押している間if文の中が通るという処理を確認 getch()関数の挙動を確認
|
8
|
+
|
3
9
|
|
4
10
|
##### debug.log
|
5
11
|
```
|
1
ソースコードを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,6 +42,10 @@
|
|
42
42
|
##### Input.cpp
|
43
43
|
```cpp
|
44
44
|
|
45
|
+
#include "Input.hpp"
|
46
|
+
#include <ncurses.h>
|
47
|
+
#include "Debug.hpp"
|
48
|
+
|
45
49
|
Console::KeyCode Console::Input::keyInput = Console::KeyCode::None;
|
46
50
|
Console::KeyCode Console::Input::prevKeyInput = Console::KeyCode::None;
|
47
51
|
bool Console::Input::flag = false;
|
@@ -53,14 +57,13 @@
|
|
53
57
|
|
54
58
|
Console::KeyCode Console::Input::GetKeyDown()
|
55
59
|
{
|
56
|
-
if(
|
60
|
+
if(flag == true)
|
57
61
|
{
|
58
|
-
flag =
|
62
|
+
flag = false;
|
59
63
|
|
60
64
|
Debug::WriteLog(" %d\n",keyInput);
|
61
65
|
|
62
66
|
return keyInput;
|
63
|
-
|
64
67
|
}
|
65
68
|
else
|
66
69
|
{
|
@@ -68,78 +71,47 @@
|
|
68
71
|
}
|
69
72
|
}
|
70
73
|
|
71
|
-
|
72
74
|
void Console::Input::InputKey()
|
73
75
|
{
|
74
|
-
|
75
|
-
|
76
76
|
|
77
77
|
int key = getch();
|
78
78
|
|
79
79
|
if(key == KEY_UP)
|
80
|
-
{
|
80
|
+
{
|
81
|
-
prevKeyInput = keyInput;
|
82
81
|
keyInput = KeyCode::Up;
|
83
82
|
}
|
84
83
|
else if(key == KEY_RIGHT)
|
85
84
|
{
|
86
|
-
prevKeyInput = keyInput;
|
87
|
-
|
88
85
|
keyInput = KeyCode::Right;
|
89
86
|
|
90
|
-
// Debug::WriteLog("keyInput %d\n",keyInput);
|
91
|
-
|
87
|
+
if(keyInput != prevKeyInput)
|
92
|
-
|
88
|
+
{
|
93
|
-
|
89
|
+
flag = true;
|
90
|
+
}
|
94
91
|
}
|
95
92
|
else if(key == KEY_DOWN)
|
96
93
|
{
|
97
|
-
prevKeyInput = keyInput;
|
98
|
-
|
99
94
|
keyInput = KeyCode::Down;
|
100
95
|
}
|
101
96
|
else if(key == KEY_LEFT)
|
102
97
|
{
|
103
|
-
prevKeyInput = keyInput;
|
104
|
-
|
105
98
|
keyInput = KeyCode::Left;
|
106
99
|
}
|
107
100
|
else if(key == KEY_ESC)
|
108
101
|
{
|
109
|
-
prevKeyInput = keyInput;
|
110
|
-
|
111
102
|
keyInput = KeyCode::Escape;
|
112
103
|
}
|
113
104
|
else if(key == KEY_RETURN)
|
114
105
|
{
|
115
|
-
prevKeyInput = keyInput;
|
116
|
-
|
117
106
|
keyInput = KeyCode::Return;
|
118
107
|
}
|
119
108
|
else
|
120
109
|
{
|
121
|
-
// 押してない時
|
122
|
-
flag = false;
|
110
|
+
flag = false;
|
123
111
|
keyInput = KeyCode::None;
|
124
112
|
prevKeyInput = KeyCode::None;
|
125
|
-
//flag = false;
|
126
|
-
//Debug::WriteLog(" KeyCode::None \n");
|
127
|
-
|
128
113
|
}
|
129
114
|
|
130
|
-
|
131
|
-
|
115
|
+
prevKeyInput = keyInput;
|
132
|
-
{
|
133
|
-
//Debug::WriteLog("keyInput %d\n",keyInput);
|
134
|
-
//Debug::WriteLog("prevKeyInput %d\n",prevKeyInput);
|
135
|
-
//Debug::WriteLog("\n\n");
|
136
|
-
|
137
|
-
}
|
138
|
-
else
|
139
|
-
{
|
140
|
-
// Debug::WriteLog("同じ %d %d\n",keyInput,prevKeyInput);
|
141
|
-
// Debug::WriteLog("\n\n");
|
142
|
-
|
143
|
-
}
|
144
116
|
}
|
145
117
|
```
|