Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a program that opens and read a character from the keyboard. If the keyboard is connected to a KVM when the keyboard switches to the another PC. My program get an error no device. So I can close the file. But what is the best way to determine that the keyboard has returned.
Do I loop trying to open the device? Is ther a way to determine that the keyboard is back?
More informatin would help: Assuming that the KVM is pointed to Computer One and you switch it to Computer Two:
Does the error appear on Computer One or Computer Two?
What precisely is the error message?
What is the program you refer to? Does this error happen if said program is not running? Does the error occur if no applications are active on either computer?
Wondering which KVM...mine don’t let the connected computer know when the keyboard “leaves” I can even boot or turn on a computer with another computer selected on the KVM with no missing keyboard errors.
I am using a Trendnet TK-409K KVM. The program that I'm running is called autopoweroff. It is a program that checks different resources
and when the conditions are met it executes a command. In my case it suspends the PC. When switching from the PC running autopoweroff
the program gets a error no such device. The program checks all keyboard and mouse devices. It does a read(1) which is what gets the error.
When the error occurs it shuts down the thread. All of this is working as it should. When you switch back to the PC running autopoweroff
it no longer monitors for activity on the keyboard and mouse. Which can cause the system to enter sleep while you are typing.
What the program should do is when it detects that the keyboard or mouse is missing. It should close the file. Sleep for some amount of
time, Then check to see if the keyboard is back. If the keyboard is back reopen the file and start monitoring again.
After some searching. I found that after switching to the other computer. The files mouse0 and mouse1 in /sys/class/input disappear. When
you switch back these two files are created. The are created as symbolic links. The program is written in python3. I've found the python3
is supposed to have the ability to check if a file exists or is a symbolic link. But the code does not wok as expected. If the symbolic link points
to a non existent file it returns false instead of true. I've tried several ways to check if the file exists. But I can't find any python3 code
that works.
The TK-409K allows me to switch between 4 PC's. As long as I don't have a program reading the keyboard or mouse
I get no errors. But if you look at the dmesg log you will see messages about the devices going away then messages when they return.
I've finally found a method that works. The file /dev/input/mouse1 disappears when you switch to the other computer and it is not a symbolic link.
The python3 code that works is Pat('/dev/input/mouse1').exists() This will return false when switched to the other computer and True when switched back.
This is what I needed.
I changed the code to look for the device that failed. When the program gets the enodev error just close the file and loop until it exists. Then open the file and continue.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.