Linux environment key detection
When I recently upgraded labwc to v0.6.5, I found that the screenshot button print had no response no matter how I pressed it.
reasons may be:
- The linked screenshot software failed;
- The button is broken;
- Problems caused by upgrading labwc.
The screenshot software I use is a combination of
grip + slurp + ksnip, which is implemented by calling the screenshot.sh script. There is no problem in actual testing.
1➜pwd 2/home/mephisto/.config/labwc 3➜cat screenshot.sh 4#!/bin/sh 5NOW=$(date +"%Y-%m-%d-%H%M%S") 6grim -g "$(slurp )" -t png $HOME/Pictures/grim-$NOW.png 7QT_QPA_PLATFORM=xcb /usr/bin/ksnip $HOME/Pictures/grim-$NOW.png
Could it be that the button is broken? My equipment costs ¥1800. Each button is worth a few dollars at least. It can’t fail so easily!
The question is, how to detect whether the
In desperation, I could only roll back to labwc. After logging in again, everything was normal. This is a big joke, there is this magical problem, targeting specific buttons and sniping at fixed points.
Ordinary people may not pursue it at this time, but when I go to bed at night, I am thinking, how can I easily detect that the button is valid?
Summarized as follows:
1. Use xev and wev
The X environment uses xev, and Wayland uses wev. Although my problem cannot be detected due to special unknowns, it is still very useful.
As shown below, I pressed the key next to Enter and 1 (it's called grave, I found out by looking at the output below 😊) The core information of the button, such as button name, key, etc., will be displayed in real time. One item will be displayed each when pressed and released.
1➜ ~wev 2[07: wl_seat] name: seat0 3[07: wl_seat] capabilities: pointer keyboard 4[10: xdg_toplevel] configure: width: 0; height: 0 5[09: xdg_surface] configure: serial: 39874 6[14: wl_keyboard] keymap: format: 1 (xkb v1), size: 63738 7[14: wl_keyboard] repeat_info: rate: 25 keys/sec; delay: 600 ms 8[14: wl_keyboard] enter: serial: 39879; surface: 3 9' sym: Return (65293), utf8: ' 10[14: wl_keyboard] modifiers: serial: 0; group: 0 11 depressed: 00000000 12 latched: 00000000 13 locked: 00000000 14[11: wl_data_device] data_offer: id: 4278190080 15[4278190080: wl_data_offer] offer: mime_type: TEXT 16[4278190080: wl_data_offer] offer: mime_type: text/plain 17[4278190080: wl_data_offer] offer: mime_type: text/plain;charset=utf-8 18[4278190080: wl_data_offer] offer: mime_type: STRING 19[4278190080: wl_data_offer] offer: mime_type: UTF8_STRING 20[11: wl_data_device] selection: id: 4278190080 21[13: wl_pointer] enter: serial: 39882; surface: 3, x, y: 197.863281, 79.218750 22[13: wl_pointer] frame 23[10: xdg_toplevel] configure: width: 0; height: 0 24 activated 25[09: xdg_surface] configure: serial: 39877 26[14: wl_keyboard] key: serial: 39883; time: 24157739; key: 36; state: 0 (released) 27 sym: Return (65293), utf8: '' 28[14: wl_keyboard] key: serial: 39884; time: 24162044; key: 49; state: 1 (pressed) 29 sym: grave (96), utf8: '`' 30[14: wl_keyboard] key: serial: 39885; time: 24162200; key: 49; state: 0 (released) 31 sym: grave (96), utf8: '' 32[14: wl_keyboard] key: serial: 39886; time: 24172492; key: 36; state: 1 (pressed) 33' sym: Return (65293), utf8: ' 34[14: wl_keyboard] key: serial: 39887; time: 24172621; key: 36; state: 0 (released) 35 sym: Return (65293), utf8: '' 36[14: wl_keyboard] key: serial: 39888; time: 24183338; key: 49; state: 1 (pressed) 37 sym: grave (96), utf8: '`' 38[14: wl_keyboard] key: serial: 39889; time: 24183480; key: 49; state: 0 (released)
2. Use showkey command
If you have entered the system graphical interface, you need to run
sudo showkey, as shown below. 99 is the print key.
1➜ ~ sudo showkey 2[sudo] password for mephisto: 3kb mode was ?UNKNOWN? 4[ if you are trying this under X, it might not work 5since the X server is also reading /dev/console ] 6 7press any key (program terminates 10s after last keypress)... 8keycode 28 release 9keycode 99 press 10keycode 99 release 11keycode 99 press 12keycode 99 release 13keycode 1 press 14keycode 1 release
If you are in the terminal environment (you can press
Ctl + Alt + F1-F7, F1-F7 to select one to switch to the terminal environment for testing), enter the password and run it directly without sudo. At this time, any keystrokes will be intercepted and you can only wait 10 seconds to exit automatically. I have never experienced this before.
In other words, showkey is the ultimate trick. It is not affected by various environments and can be used to detect whether the keys are physically damaged.
Some people may ask, shouldn't it be better if I just find a place where I can type characters and see if the characters on the screen are correct? This cannot detect various function keys such as
Some people will say that I am an embedded engineer and it is indeed possible to write programs to detect and solve problems. But showkey has been around for a long time, and it doesn’t waste time to use it.
In summary, use xev and wev for simple keyboard detection, and showkey in special cases.
Finally, the screenshot triggered by the new version of labwc is invalid. It is estimated that there is an exception when the script screenshot.sh is added. There is no simple debugging method, so roll back to solve it first. labwc is a binary program, and it is not troublesome to replace it directly.
- All content on this site is original, please do not reprint without authorization (because the typesetting is often disordered after reprinting, the content is uncontrollable, and cannot be continuously updated, etc.);
- For non-profit purposes, to deduce any content of this blog, please give the relevant webpage address of this site in the form of 'source of original text' or 'reference link' (for the convenience of readers).
- Snipe it asset management system installation and use
- Wayland environment ksnip cannot be copied problem solved
- Screenshot plus post-modification in Wayland environment
- Gif screen recording in Wayland environment
- Wofi Tutorial
- Application launcher yofi configuration
- Batch conversion of Simplified Chinese articles to Traditional Chinese
- Install the latest version of Python for Linux
- Ubuntu 22.10 connection bluetooth headset error 'br-connection-profile-unavailable solution'
- Minetest demo