471,896 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,896 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 6148
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by John Smith | last post: by
2 posts views Thread by Michael Bendzick | last post: by
1 post views Thread by Scott Shaw | last post: by
1 post views Thread by Starbase Commander | last post: by
6 posts views Thread by robert | last post: by
2 posts views Thread by Brice Rebsamen | last post: by
1 post views Thread by Rebles | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

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.