-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkeybd.c
39 lines (35 loc) · 1.03 KB
/
keybd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "keybd.h"
#include "syscall.h"
#define HIGH 1
#define LOW 0
void init_keybd(const IOInterface *interface, int rows, int cols)
{
for(int r=0; r<rows; r++)
interface->write_row(r, HIGH);
}
void scan_keybd(const IOInterface *interface, int rows, int cols, int result[rows][cols])
{
for(int r = 0; r < rows; r++) {
interface->write_row(r, LOW);
sleep(0);
for(int c = 0; c < cols; c++) {
result[r][c] = !interface->read_col(c);
}
interface->write_row(r, HIGH);
}
}
void update_keybd_event(int rows, int cols, int last_result[rows][cols], int result[rows][cols], KeyEvent event[rows][cols])
{
for(int r=0; r<rows; r++) {
for(int c=0; c<cols; c++) {
if(last_result[r][c]!=result[r][c]) {
if(result[r][c])
event[r][c] = KEY_DOWN;
else
event[r][c] = KEY_UP;
last_result[r][c] = result[r][c];
} else
event[r][c] = UNCHANGED;
}
}
}