How to scan Keyboard in Perl or else on Linux ?

Discussion in 'Perl' started by =?ISO-8859-1?Q?Rapha=EBl?=, Nov 4, 2004.

  1. 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?Rapha=EBl?=, Nov 4, 2004
    #1
    1. Advertising

  2. Raphaël <> 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
     
    =?iso-8859-1?q?M=E5ns_Rullg=E5rd?=, Nov 4, 2004
    #2
    1. Advertising

  3. 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 <> 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.
    >
     
    =?ISO-8859-1?Q?Rapha=EBl?=, Nov 9, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Bendzick

    Reading Keyboard Scan Codes

    Michael Bendzick, Jul 23, 2003, in forum: Python
    Replies:
    2
    Views:
    1,405
    Alan Gauld
    Jul 24, 2003
  2. Bjorn Pettersen

    RE: Reading Keyboard Scan Codes

    Bjorn Pettersen, Jul 23, 2003, in forum: Python
    Replies:
    0
    Views:
    551
    Bjorn Pettersen
    Jul 23, 2003
  3. Francois Pinard

    Re: Reading Keyboard Scan Codes

    Francois Pinard, Jul 24, 2003, in forum: Python
    Replies:
    0
    Views:
    530
    Francois Pinard
    Jul 24, 2003
  4. Replies:
    25
    Views:
    702
    MonkeeSage
    Oct 1, 2006
  5. Raphaël
    Replies:
    3
    Views:
    160
    Raphaël
    Nov 9, 2004
Loading...

Share This Page