LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 09-15-2020, 11:42 AM   #1
rac8006
LQ Newbie
 
Registered: Oct 2014
Posts: 24

Rep: Reputation: Disabled
reading keyboard


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?

Thanks
 
Old 09-15-2020, 07:35 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 16,588
Blog Entries: 27

Rep: Reputation: 5030Reputation: 5030Reputation: 5030Reputation: 5030Reputation: 5030Reputation: 5030Reputation: 5030Reputation: 5030Reputation: 5030Reputation: 5030Reputation: 5030
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?
 
Old 09-15-2020, 08:00 PM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.8.2003
Posts: 5,152

Rep: Reputation: 1876Reputation: 1876Reputation: 1876Reputation: 1876Reputation: 1876Reputation: 1876Reputation: 1876Reputation: 1876Reputation: 1876Reputation: 1876Reputation: 1876
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.
 
Old 09-15-2020, 10:36 PM   #4
rac8006
LQ Newbie
 
Registered: Oct 2014
Posts: 24

Original Poster
Rep: Reputation: Disabled
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.
 
Old 09-15-2020, 10:38 PM   #5
rac8006
LQ Newbie
 
Registered: Oct 2014
Posts: 24

Original Poster
Rep: Reputation: Disabled
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.
 
Old 09-15-2020, 11:41 PM   #6
rac8006
LQ Newbie
 
Registered: Oct 2014
Posts: 24

Original Poster
Rep: Reputation: Disabled
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.

Last edited by rac8006; 09-21-2020 at 05:47 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux read(): after reading 20 bytes, reading again get "Resource temporarily unavail esolve Programming 2 10-20-2015 08:02 AM
NginX [error] upstream prematurely closed connection while reading reading response kingkashif Linux - Server 2 07-20-2013 04:37 PM
Microsoft Visual C++, Reading from File, Reading an XFile not heirarchy Soulkeeper1987 Programming 1 07-01-2012 04:09 PM
My dvd drive is not mounting and reading. No udf based dvd is not reading. anjanatsuse Linux - Newbie 1 10-15-2010 12:54 PM
scanf reading newline into char array while reading 1 char at a time austinium Programming 6 09-26-2010 11:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration