-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change from ASWD keys to arrow keys to move the numbers #2
Comments
Possibility of using arrows keys or asdw. Modified number of movements. Alphabetical arrangement of headers.
Possibility of using arrows keys or asdw. Modified number of movements. Alphabetical arrangement of headers.
I will try implementing the arrow key functionality for Linux |
You should use termios.h library but as I said before you Will change the terminal properties. #include <stdio.h>
#include <termios.h>
#include <unistd.h>
char getch() {
char buf = 0;
struct termios old = {0};
if (tcgetattr(0, &old) < 0)
perror("tcsetattr()");
old.c_lflag &= ~ICANON;
old.c_lflag &= ~ECHO;
old.c_cc[VMIN] = 1;
old.c_cc[VTIME] = 0;
if (tcsetattr(0, TCSANOW, &old) < 0)
perror("tcsetattr ICANON");
if (read(0, &buf, 1) < 0)
perror("read()");
old.c_lflag |= ICANON;
old.c_lflag |= ECHO;
if (tcsetattr(0, TCSADRAIN, &old) < 0)
perror("tcsetattr ~ICANON");
return buf;
}
int main() {
printf("Press a key: ");
char c = getch();
printf("\nYou pressed: %c\n", c);
return 0;
} |
I have added arrow key feature in Linux. |
The arrow key work properly on linux. do
{
for (int i = 0; i < 5; i++)
key_pressed[i] = '\0';
scanf("%4s",key_pressed);
clear_input_buffer();
// Get key pressed.
if (toupper(key_pressed[0]) == 'A' || toupper(key_pressed[0]) == 'S' ||
toupper(key_pressed[0]) == 'D' || toupper(key_pressed[0]) == 'W')
*direction = key_pressed[0];
// Arrow keys are converted into ^[[A, [[B, [[C, [[C on linux. ^[ = Esc.
else if (toupper(key_pressed[0]) == 27 && toupper(key_pressed[1]) == '[') // 27 = Esc
{
switch(toupper(key_pressed[2]))
{
case 'A': *direction = 'w'; break;
case 'B': *direction = 's'; break;
case 'C': *direction = 'd'; break;
case 'D': *direction = 'a'; break;
default: *direction = 'e'; break; // no asdw no arrow key pressed.
}
}
else
*direction = 'e';
} while (*direction == 'e'); |
Okeii.. will check for sure.. |
I don't know who it will behave because i had to press enter after each key pressed. |
In place of using ASWD keys to move around the numbers i want to use the arrow keys but i can not figure out how to do it.. If you can really solve the problem go for it. Give it a try
The text was updated successfully, but these errors were encountered: