473,388 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to scan Keyboard in Perl or else on Linux ?

Hi,

On Linux, does somebody know how to get the keyboard status in Perl ?

I explane :
-> I would like to write a Perl script which scan the keyboard and
return the list of pressed keys.

For example, let "keyboard_scan()" be the name of this function, with
the following behavior:

- When keyboard_scan() is called, if the user is pressing no keys, I
would like keyboard_scan() to return the empty string "".
- When keyboard_scan() is called, if the user is pressing the CTRL key,
I would like keyboard_scan() to return the code string of the CTRL key.
- When keyboard_scan() is called, if the user is pressing the ALT key
and the SHIFT key, I would like the function to return the string
containing the code of the SHIFT key and the code of the ALT key.
etc ...

Or perhaps somebody knows how to do it in another language (C, TCL, ...) ?

Thanks !

Raphaël.
Jul 19 '05 #1
2 6298
Raphaël <Ra************@xilinx.com> writes:
Hi,

On Linux, does somebody know how to get the keyboard status in Perl ?

I explane :
-> I would like to write a Perl script which scan the keyboard and
return the list of pressed keys.

For example, let "keyboard_scan()" be the name of this function, with
the following behavior:

- When keyboard_scan() is called, if the user is pressing no
keys, I would like keyboard_scan() to return the empty string
"".
- When keyboard_scan() is called, if the user is pressing the
CTRL key, I would like keyboard_scan() to return the code
string of the CTRL key.
- When keyboard_scan() is called, if the user is pressing the
ALT key and the SHIFT key, I would like the function to return
the string containing the code of the SHIFT key and the code
of the ALT key.
etc ...

Or perhaps somebody knows how to do it in another language (C, TCL, ...) ?


Are you running under X? Look at the source of xkbwatch. It displays
the status of the modifier keys.

--
Måns Rullgård
mr*@inprovide.com
Jul 19 '05 #2
Hi,

I didn't find what I needed even in the ReadKey CPAN package ... so I
finally followed the Måns advise even if it's not portable to none unix
platforms.

I checked how is done the xkbwatch source code and I wrote my own
procedure (mainly because I don't need the xkbwatch graphical interface).

Now I call it from my perl script and it works fine !

Thanks everybody,

Raphaël.

Måns Rullgård wrote:
Raphaël <Ra************@xilinx.com> writes:

Hi,

On Linux, does somebody know how to get the keyboard status in Perl ?

I explane :
-> I would like to write a Perl script which scan the keyboard and
return the list of pressed keys.

For example, let "keyboard_scan()" be the name of this function, with
the following behavior:

- When keyboard_scan() is called, if the user is pressing no
keys, I would like keyboard_scan() to return the empty string
"".
- When keyboard_scan() is called, if the user is pressing the
CTRL key, I would like keyboard_scan() to return the code
string of the CTRL key.
- When keyboard_scan() is called, if the user is pressing the
ALT key and the SHIFT key, I would like the function to return
the string containing the code of the SHIFT key and the code
of the ALT key.
etc ...

Or perhaps somebody knows how to do it in another language (C, TCL, ...) ?

Are you running under X? Look at the source of xkbwatch. It displays
the status of the modifier keys.

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question...
2
by: Michael Bendzick | last post by:
Is there a simple way in python to read a keyboard scan code? I'm working on a shell script that interfaces with a proprietary keyboard device (extra buttons) and need to be able to distinguish...
3
by: David F. Skoll | last post by:
Hi, I'm tearing my hair out on this one. I'm trying to embed a Perl interpreter into a C program. I need to be able to create and destroy the interpreter periodically, but will never actually...
1
by: Scott Shaw | last post by:
Hi all, I was wondering if you could help out with this problem that I am having. What I am trying to do is detect keyboard input in a while loop without halting/pausing the loop until the key is...
1
by: Starbase Commander | last post by:
My Perl books don't explain how to receive single keystrokes in real time, like the basic statement "inkey$" or C statement "getc" - probably because I assume it requires a specific system call...
6
by: robert | last post by:
just got out of a "class" on EXPLAIN, from a 390/v6 maven. was told that ACCESSTYPE = 'R' in the plan_table meant a TableSpace scan. hmmmm. next step up (or down, depending on your outlook)...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
2
by: Brice Rebsamen | last post by:
Hi I wrote the following program that reads the keyboard in medium raw mode (keycode mode). Here is the initialization code, the full code is at the end. fd = open("/dev/tty0", O_RDONLY);...
1
by: Rebles | last post by:
Hi, I just posted this in the MS SQL Section, but maybe my problem is rooted in Perl, so it's more appropriate to post here instead (sorry for the double post) I'm writing a PERL script to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.