From dd4a94412ce6bb7a76fed471568099a8df2d211c Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Sun, 10 Nov 2019 22:38:25 +0100 Subject: 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 --- src/cInput.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/cInput.cpp') 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]; } -- cgit v1.2.3