aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-11-10 22:38:25 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-11-10 22:38:25 +0100
commitdd4a94412ce6bb7a76fed471568099a8df2d211c (patch)
treec819c8f4b08b1c5d14e8e46b2600d069d2bf6428
parent5944d774a468ebc8b7c2d30c5f600bcf0ceb1532 (diff)
downloadtermgl-dd4a94412ce6bb7a76fed471568099a8df2d211c.tar.gz
cInput: Added _EVENT_CTRL and CTRL_KEY() Macro
_EVENT_CTRL triggers, when CTRL + key has been pressed. Compare to CTRL_KEY( char ) _EVENT_TERM is still usable, but use is discouraged
-rw-r--r--src/cInput.cpp14
-rw-r--r--src/cInput.h15
2 files changed, 20 insertions, 9 deletions
diff --git a/src/cInput.cpp b/src/cInput.cpp
index b11bbb5..552674f 100644
--- a/src/cInput.cpp
+++ b/src/cInput.cpp
@@ -27,6 +27,7 @@ sInputEvent cInput::poll()
sInputEvent ret;
unsigned char buff [buff_len];
+ //TODO maybe poll()?
//setup for select
fd_set rfds;
struct timeval tv;
@@ -42,9 +43,14 @@ sInputEvent cInput::poll()
return ret;
read (STDIN_FILENO, &buff, 1);
- if (buff[0] == 3) {
- // User pressd Ctr+C
- ret.type = _EVENT_TERM;
+ if (buff[0] && buff[0] <= 26) {
+ //Ctrl keys are 1-26. check with CTRL_KEY( ) Macro
+ ret.type = _EVENT_CTRL;
+ ret.c = buff[0];
+
+ //To not break compatability
+ if (buff[0] == CTRL_KEY('c'))
+ ret.type = _EVENT_TERM;
}
else if (buff[0] == '\x1B') //Escape sequence
{
@@ -71,7 +77,7 @@ sInputEvent cInput::poll()
}
}
else
- {
+ {
ret.type = _EVENT_CHAR;
ret.c = buff[0];
}
diff --git a/src/cInput.h b/src/cInput.h
index dd9866c..3507959 100644
--- a/src/cInput.h
+++ b/src/cInput.h
@@ -13,12 +13,16 @@
#error "Platforn not supported"
#endif
-#define _EVENT_NULL 0
-#define _EVENT_CHAR 1
+//Macro, to get keycode of Ctrl-(k)
+#define CTRL_KEY(k) ((k) & 0x1f)
+
+#define _EVENT_NULL 0
+#define _EVENT_CHAR 1
#define _EVENT_KEY 2
-#define _EVENT_MOUSE 3
-#define _EVENT_TERM 4
+#define _EVENT_MOUSE 3
+#define _EVENT_TERM 4 //Obsolete
#define _EVENT_FUNCTION1 5
+#define _EVENT_CTRL 6
struct sInputEvent
{
@@ -48,8 +52,9 @@ public:
* * _EVENT_CHAR: A Key was pressed, stored in .c
* * _EVENT_KEY: Escape sequence recorded, stored in .c without escape char
* * _EVENT_MOUSE: Console registered click at (.x, .y) with origin at (0,0) (top left). Mouse button stored in b.
- * * _EVENT_TERM: Console registered Ctrl+C
+ * * _EVENT_TERM: Console registered Ctrl+C. **OBSOLETE** use _EVENT_CTRL
* * _EVENT_FUNCTION1: First few (4?) F-Keys. The rest of the F-Keys is handles by another ESC-Sequence!
+ * * _EVENT_CTRL: Ctrl-key combination was pressed. Use CTRL_KEY( ) Macro to compare
*/
sInputEvent poll();