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

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

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

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,628
    Alan Gauld
    Jul 24, 2003
  2. Replies:
    25
    Views:
    958
    MonkeeSage
    Oct 1, 2006
  3. kj
    Replies:
    15
    Views:
    794
    Lawrence D'Oliveiro
    May 23, 2009
  4. A
    Replies:
    8
    Views:
    1,051
    James Kanze
    Aug 28, 2010
  5. Gergely Kontra
    Replies:
    16
    Views:
    413
    Devin Mullins
    Sep 20, 2005
  6. Raphaël
    Replies:
    3
    Views:
    245
    Raphaël
    Nov 9, 2004
  7. Krishna Chaitanya
    Replies:
    1
    Views:
    270
    Krishna Chaitanya
    Feb 27, 2009
  8. KDawg44

    Running NMap Scan from Perl

    KDawg44, Feb 5, 2010, in forum: Perl Misc
    Replies:
    1
    Views:
    196
    Martijn Lievaart
    Feb 5, 2010
Loading...