How to scan Keyboard in Perl or else on Linux ?

  • Thread starter =?ISO-8859-1?Q?Rapha=EBl?=
  • Start date
?

=?ISO-8859-1?Q?Rapha=EBl?=

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.
 
?

=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=

Raphaël said:
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.
 
?

=?ISO-8859-1?Q?Rapha=EBl?=

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top