diff --git a/src/logkeys.cc b/src/logkeys.cc index fe90ffe..30ea3c0 100644 --- a/src/logkeys.cc +++ b/src/logkeys.cc @@ -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 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 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()); } } }