2021-10-15 18:55:41 +00:00
|
|
|
#include <errno.h>
|
2020-08-17 13:50:39 +00:00
|
|
|
#include "evdev.h"
|
|
|
|
|
|
|
|
|
|
|
|
int block_until_keypress(const char* keyboardPath) {
|
|
|
|
int keyboardFd = open(keyboardPath, O_RDONLY);
|
|
|
|
if (keyboardFd < 0) {
|
2021-10-15 18:55:41 +00:00
|
|
|
return errno;
|
2020-08-17 13:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int eventSize = sizeof(struct input_event);
|
|
|
|
int bytesRead = 0;
|
|
|
|
struct input_event events[NUM_EVENTS];
|
|
|
|
|
|
|
|
int readEvents = 1;
|
|
|
|
while(readEvents) {
|
|
|
|
bytesRead = read(keyboardFd, events, eventSize * NUM_EVENTS);
|
|
|
|
if (bytesRead < 0) {
|
2021-10-15 18:55:41 +00:00
|
|
|
return errno;
|
2020-08-17 13:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < (bytesRead / eventSize); ++i) {
|
|
|
|
struct input_event event = events[i];
|
|
|
|
if(event.type == EV_KEY) {
|
|
|
|
if(event.value == 1) {
|
|
|
|
readEvents = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(keyboardFd);
|
|
|
|
return 0;
|
|
|
|
}
|