Commit aa081269 authored by kernc's avatar kernc

Hopefully fixes issue http://code.google.com/p/logkeys/issues/detail?id=42...

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
parent ef5f0a18
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#endif #endif
#define COMMAND_STR_DUMPKEYS ( EXE_DUMPKEYS " -n | " EXE_GREP " '^\\([[:space:]]shift[[:space:]]\\)*\\([[:space:]]altgr[[:space:]]\\)*keycode'" ) #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 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 #define INPUT_EVENT_PATH "/dev/input/" // standard path
...@@ -333,42 +333,22 @@ void determine_input_device() ...@@ -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.) // 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::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::vector<std::string> results;
std::string line; std::string line;
int index;
bool name_ok = false;
while(std::getline(output, line)) { while(std::getline(output, line)) {
if (line[0] == 'N') { // N: Name="AT Translated Set 2 keyboard" std::string::size_type i = line.find("event");
name_ok = false; if (i != std::string::npos) i += 5; // "event".size() == 5
for (unsigned i = 0; i < valid_device_names.size(); ++i) { if (i < line.size()) {
if (line.find(valid_device_names[i]) != std::string::npos) { int index = atoi(&line.c_str()[i]);
name_ok = true;
break; if (index != -1) {
} std::stringstream input_dev_path;
} input_dev_path << INPUT_EVENT_PATH;
} input_dev_path << "event";
else if (name_ok && line[0] == 'H') { // H: Handlers=kbd event4 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()) {
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());
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment