Hopefully fixes issue http://code.google.com/p/logkeys/issues/detail?id=42 (Couldn't determine keyboard device). We have a new heuristic! :D

git-svn-id: https://logkeys.googlecode.com/svn/trunk@92 c501e62c-e7d1-11de-a198-37193048d1ed
This commit is contained in:
kernc 2012-01-04 19:22:09 +00:00
parent ef5f0a18a4
commit aa0812690d
1 changed files with 12 additions and 32 deletions

View File

@ -46,7 +46,7 @@
#endif
#define COMMAND_STR_DUMPKEYS ( EXE_DUMPKEYS " -n | " EXE_GREP " '^\\([[:space:]]shift[[:space:]]\\)*\\([[:space:]]altgr[[:space:]]\\)*keycode'" )
#define COMMAND_STR_DEVICES ( EXE_GREP " -E 'Name|Handlers' /proc/bus/input/devices" )
#define COMMAND_STR_DEVICES ( EXE_GREP " -E 'Handlers|EV=' /proc/bus/input/devices | " EXE_GREP " -B1 'EV=120013' | " EXE_GREP " -Eo 'event[0-9]+' ")
#define COMMAND_STR_GET_PID ( (std::string(EXE_PS " ax | " EXE_GREP " '") + program_invocation_name + "' | " EXE_GREP " -v grep").c_str() )
#define INPUT_EVENT_PATH "/dev/input/" // standard path
@ -333,42 +333,22 @@ void determine_input_device()
// extract input number from /proc/bus/input/devices (I don't know how to do it better. If you have an idea, please let me know.)
std::stringstream output(execute(COMMAND_STR_DEVICES));
std::vector<std::string> valid_device_names;
valid_device_names.push_back("keyboard");
valid_device_names.push_back("Keyboard");
valid_device_names.push_back("HID");
valid_device_names.push_back("Microsoft");
std::vector<std::string> results;
std::string line;
int index;
bool name_ok = false;
while(std::getline(output, line)) {
if (line[0] == 'N') { // N: Name="AT Translated Set 2 keyboard"
name_ok = false;
for (unsigned i = 0; i < valid_device_names.size(); ++i) {
if (line.find(valid_device_names[i]) != std::string::npos) {
name_ok = true;
break;
}
}
}
else if (name_ok && line[0] == 'H') { // H: Handlers=kbd event4
std::string::size_type i = line.find("event");
if (i != std::string::npos) i += 5; // "event".size() == 5
if (i < line.size()) {
index = atoi(&line.c_str()[i]);
if (index != -1) {
std::stringstream input_dev_path;
input_dev_path << INPUT_EVENT_PATH;
input_dev_path << "event";
input_dev_path << index;
std::string::size_type i = line.find("event");
if (i != std::string::npos) i += 5; // "event".size() == 5
if (i < line.size()) {
int index = atoi(&line.c_str()[i]);
if (index != -1) {
std::stringstream input_dev_path;
input_dev_path << INPUT_EVENT_PATH;
input_dev_path << "event";
input_dev_path << index;
results.push_back(input_dev_path.str());
}
results.push_back(input_dev_path.str());
}
}
}