-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also, edited the LuaScript source to remove some irritating false errors when running WeJoy, and some other clean up which I do not remember.
- Loading branch information
Showing
8 changed files
with
181 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "CKeyboard.h" | ||
//#include <libudev.h> | ||
//#include <stdio.h> | ||
#include <string.h> | ||
#include <unistd.h> //usleep | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
#include <linux/input.h> | ||
|
||
|
||
CKeyboard::CKeyboard(std::string _eventPath) | ||
{ | ||
eventPath = _eventPath; | ||
fd = open(eventPath.c_str(), O_RDONLY); | ||
if(fd == -1) | ||
{ | ||
fprintf(stderr, "KEYBOARD: Cannot open %s: %s.\n", eventPath.c_str(), strerror(errno)); | ||
} | ||
} | ||
|
||
CKeyboard::~CKeyboard() | ||
{ | ||
if(fd>-1) close(fd); | ||
} | ||
|
||
std::string CKeyboard::getEventPath() | ||
{ | ||
return eventPath; | ||
} | ||
|
||
bool CKeyboard::isOpen() | ||
{ | ||
if(fd>-1) return true; | ||
|
||
return false; | ||
} | ||
|
||
bool CKeyboard::readEvent(CKeyboardEvent* _keyEvent) | ||
{ | ||
/* | ||
static const char *const evval[3] = { | ||
"RELEASED", | ||
"PRESSED ", | ||
"REPEATED" | ||
}; | ||
*/ | ||
|
||
if(fd<0) return false; | ||
|
||
struct input_event ev; | ||
ssize_t n; | ||
n = read(fd, &ev, sizeof ev); | ||
if(n == ((ssize_t) - 1) || n!= sizeof(ev)) return false; | ||
|
||
if(ev.type == EV_KEY && ev.value>=0 && ev.value<=2 && ev.value!=2) | ||
{ | ||
_keyEvent->isPressed = ev.value; | ||
_keyEvent->code = ev.code; | ||
//printf("%s 0x%04x (%d) %d\n", evval[ev.value], (int)ev.code, (int)ev.code, (ev.code == KEY_Q ? 1 : 0)); | ||
return true; | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef CKEYBOARD_HEADER | ||
#define CKEYBOARD_HEADER | ||
|
||
#include <string> | ||
|
||
|
||
class CKeyboardEvent | ||
{ | ||
public: | ||
bool isPressed; | ||
char code; | ||
}; | ||
|
||
class CKeyboard | ||
{ | ||
private: | ||
int fd = -1; | ||
std::string eventPath; | ||
|
||
public: | ||
std::string getEventPath(); | ||
bool isOpen(); | ||
bool readEvent(CKeyboardEvent*); | ||
|
||
CKeyboard(std::string eventPath); | ||
~CKeyboard(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/sh | ||
#g++ -ludev suinput.o -o test main.cc -Wall | ||
#g++ -Wall -std=c++11 -ludev -lpthread -lX11 -llua5.2 suinput.c joystick.cc LuaScript.cc CVirtualJoy.cc CVirtualKeyboard.cc -o wejoy main.cc | ||
g++ -Wall -std=c++11 suinput.c joystick.cc LuaScript.cc CVirtualJoy.cc CVirtualKeyboard.cc -o wejoy main.cc -ludev -lpthread -lX11 -llua5.2 | ||
g++ -Wall -std=c++11 suinput.c joystick.cc CKeyboard.cc LuaScript.cc CVirtualJoy.cc CVirtualKeyboard.cc -o wejoy main.cc -ludev -lpthread -lX11 -llua5.2 | ||
#g++ test.cc joystick.cc -std=c++0x -Wall -o test |