BUU has asked for the wisdom of the Perl Monks concerning the following question:

Basically I've been playing with Term::ReadKey and such and I'd like to trap the arrow keys on win32 (preferably cross platform as well) and I can't seem to make Term::ReadKey's ReadKey or anything similar. I've been examing the source of Term::ReadLine which appears to capture the arrow keys some how, but so far I can't figure it out. I've also been looking at Win32::Console but I haven't see anything useful there either.

In short, anyone have some working code, or at least a better idea where to search, to capture the arrow keys in a win32 cmd console?
  • Comment on Capturing arrow keys on win32, crossplatform

Replies are listed 'Best First'.
Re: Capturing arrow keys on win32, crossplatform
by BrowserUk (Patriarch) on Jan 16, 2005 at 12:35 UTC

    The best reference for Win32::Console is the file test.pl that comes with it. Specifically, it has code that demos using the cursor keys.

    ( Please do not upvote this node. Dave Roth wrote the code, I just remembered where it was!)


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
Re: Capturing arrow keys on win32, crossplatform
by PodMaster (Abbot) on Jan 16, 2005 at 12:03 UTC
    at least a better idea where to search, to capture the arrow keys in a win32 cmd console?
    Who makes and provides the win32 cmd console?
    Right, microsoft.
    So where should you search?
    Right, microsoft.
    Remember this advice, if you want to know about product X simply ask the-maker-of-product-X.

    microsoft console read arrow key => high level console input and output functions <> low level console input functions <> console structures <> key_event_record_str =>

    Enhanced keys for the IBM® 101- and 102-key keyboards are the INS, DEL, HOME, END, PAGE UP, PAGE DOWN, and direction keys in the clusters to the left of the keypad; and the divide (/) and ENTER keys in the keypad
    Now you can reach for Win32::API, or enhance Term::ReadKey or whatever.

    update: As far as portability goes, I'd look into Curses.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Capturing arrow keys on win32, crossplatform
by Washizu (Scribe) on Jan 17, 2005 at 14:46 UTC
    Check out one of my old nodes about a very similar problem. There are some problems with ReadKey on Windows for certain keys (arrow keys, delete, etc.). Sorry for not being much of a help, but you're not the only one with this problem.

    -----------------------------------
    Washizu
    Acoustic Rock + games