How to scan Keyboard in Perl or else on Linux ?

Discussion in 'Perl Misc' started by Raphaël, Nov 4, 2004.

  1. Raphaël

    Raphaël Guest

    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.
     
    Raphaël, 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
     
    Måns Rullgård, Nov 4, 2004
    #2
    1. Advertising

  3. Raphaël <> wrote:

    > does somebody know how to get the keyboard status in Perl ?



    Have you already seen the 3 Perl FAQs about keyboards?

    perldoc -q keyboard

    How can I read a single character from a file? From the keyboard?
    How do I do fancy stuff with the keyboard/screen/mouse?
    How do I check whether input is ready on the keyboard?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Nov 4, 2004
    #3
  4. Raphaël

    Raphaël Guest

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

    How to scan Keyboard in Perl or else on Linux ?

    =?ISO-8859-1?Q?Rapha=EBl?=, Nov 4, 2004, in forum: Perl
    Replies:
    2
    Views:
    885
    =?ISO-8859-1?Q?Rapha=EBl?=
    Nov 9, 2004
  2. Michael Bendzick

    Reading Keyboard Scan Codes

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

    RE: Reading Keyboard Scan Codes

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

    Re: Reading Keyboard Scan Codes

    Francois Pinard, Jul 24, 2003, in forum: Python
    Replies:
    0
    Views:
    506
    Francois Pinard
    Jul 24, 2003
  5. Replies:
    25
    Views:
    672
    MonkeeSage
    Oct 1, 2006
Loading...

Share This Page