cxev 637 B

12345678910111213141516171819202122232425262728293031
  1. #!/bin/sh
  2. compat=""
  3. if awk --version | grep -q GNU; then
  4. # This is for hex-to-decimal conversion.
  5. compat="--non-decimal"
  6. fi
  7. xev "$@" | awk $compat '/KeyPress|KeyRelease/ {
  8. if ($1 == "KeyPress")
  9. event="pressed";
  10. else
  11. event="released";
  12. getline; getline;
  13. state = substr($2,1,length($2)-2);
  14. keycode = $4;
  15. keysym = substr($7, 1, length($7)-2);
  16. printf "%-16s code=%-3s state=%s event=%-8s", keysym, keycode, state, event
  17. getline;
  18. gsub(/\(|\)/, "", $5)
  19. code=int(sprintf("%d", "0x" $5))
  20. if (code > 32 && code != 127) {
  21. /* Ignore non-printable characters" */
  22. gsub(/"/, "", $NF)
  23. printf " string=%s", $NF
  24. }
  25. print ""
  26. }'