Skip to content

Commit c090fe8

Browse files
committed
Reorganize code
1 parent fe1a1d3 commit c090fe8

8 files changed

Lines changed: 48 additions & 24 deletions

File tree

‎c/getch/CMakeLists.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.9)
22
PROJECT(GETCH)
33
INCLUDE_DIRECTORIES(./include)
44
AUX_SOURCE_DIRECTORY(./src DIR_SRCS)
5-
ADD_EXECUTABLE(bin ${DIR_SRCS})
5+
ADD_EXECUTABLE(getch ${DIR_SRCS})

‎c/getch/include/getch.c‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎c/getch/include/keyboard.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define ESC 0x1B

‎c/getch/src/main.c‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎c/getch/test/CMakeLists.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.9)
2+
PROJECT(TEST)
3+
INCLUDE_DIRECTORIES(../include)
4+
AUX_SOURCE_DIRECTORY(./ DIR_SRCS)
5+
ADD_EXECUTABLE(test ${DIR_SRCS})

‎c/getch/test/test.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// test
2+
#include "getch.h"
3+
#include "keyboard.h"
4+
#include <stdio.h>
5+
int sh_getch(void);
6+
int main() {
7+
char ch;
8+
do {
9+
ch = sh_getch();
10+
switch (ch) {
11+
case 'w':
12+
printf("You press w\n");
13+
break;
14+
case 'a':
15+
printf("You press a\n");
16+
break;
17+
case 's':
18+
printf("You press s\n");
19+
break;
20+
case 'd':
21+
printf("You press d\n");
22+
break;
23+
}
24+
} while (ch != ESC);
25+
printf("ch:\'%c'\nExiting......", ch);
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.9)
2+
PROJECT(GETKEYVALUE)
3+
INCLUDE_DIRECTORIES(../../include)
4+
AUX_SOURCE_DIRECTORY(./ DIR_SRCS)
5+
ADD_EXECUTABLE(getkey ${DIR_SRCS})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "getch.h"
2+
#include <stdio.h>
3+
int sh_getch(void);
4+
int main() {
5+
char ch;
6+
while ((ch = sh_getch()) != 0x1B) /* ESC to quit */
7+
{
8+
printf("%d \n", ch);
9+
}
10+
}

0 commit comments

Comments
 (0)