단일 키 입력을 받는 코드
cpp로 왜 안되나 봤더니, _getch() 때문에 안되는거였나?
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <conio.h>
int main() {
int key1 = 0;
//int dummy = 0;
int key_state = 0;
printf("Press 1 key\\r\\n");
while (1) {
//dummy = scanf("%d", &key1);
key1 = _getch();
//printf("%d", key1);
if (key1 == '1') {
if (key_state == 0) {
key_state = 1;
}
else {
key_state = 0;
}
}
if (key_state == 0) {
printf("off\\r\\n");
}
else if (key_state == 1) {
printf("on\\r\\n");
}
}
return 0;
}
▼ 키보드의 키 코드 리스트
https://blog.naver.com/eversir/110032142106
이거 안맞는거 같은데?
▼ 키보드 키 및 키 코드 값 (Keyboard key and keycode)