Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7798285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:57:43+00:00 2026-06-01T23:57:43+00:00

When I press the Up -key, this script ( Term::TermKey ) outputs You pressed:

  • 0

When I press the Up-key, this script (Term::TermKey) outputs You pressed: <Up> .

#!/usr/bin/env perl
use warnings;
use 5.012;
use Term::TermKey;

my $tk = Term::TermKey->new( \*STDIN );
say "Press any key";
$tk->waitkey( my $key );
say "You pressed: <" . $tk->format_key( $key, 0 ) . ">";

How could I reach the same result with Win32::Console?
I tried this, but it worked only on “normal” keys like l,k, … but not with keys like Up, Delete, …

use Win32::Console;

my $in = Win32::Console->new(STD_INPUT_HANDLE);
$in->Mode(ENABLE_PROCESSED_INPUT);
my $result = $in->InputChar(1);
say "<$result>";

How could I make work keys like Up, Delete, … too with Win32::Console?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:57:44+00:00Added an answer on June 1, 2026 at 11:57 pm

    The up key does not result in a character. InputChar cannot possible return it. You need to use Input.

    my $con_in = Win32::Console->new(STD_INPUT_HANDLE);
    for (;;) {
       my @event = $con_in->Input();
    
       my $event_type = shift(@event);
       next if !defined($event_type) || $event_type != 1;  # 1: Keyboard
    
       my ($key_down, $repeat_count, $vkcode, $vscode, $char, $ctrl_key_state) = @event;
       if ($vkcode == VK_UP && ($ctrl_key_state & SHIFTED_MASK) == 0) {
          if ($key_down) {
             say "<Up> pressed/held down" for 1..$repeat_count;
          } else {
             say "<Up> released";
          }
       }
    }
    

    See KEY_EVENT_RECORD for more information about keyboard events.

    See Virtual-Key Codes to identify keys.


    Headers and definitions for above code:

    use strict;
    use warnings;
    use feature qw( say );
    
    use Win32::Console qw( STD_INPUT_HANDLE );
    
    use constant {
       RIGHT_ALT_PRESSED  => 0x0001,
       LEFT_ALT_PRESSED   => 0x0002,
       RIGHT_CTRL_PRESSED => 0x0004,
       LEFT_CTRL_PRESSED  => 0x0008,
       SHIFT_PRESSED      => 0x0010,
    
       VK_UP => 0x26,
    };
    
    use constant SHIFTED_MASK =>
       RIGHT_ALT_PRESSED |
       LEFT_ALT_PRESSED |
       RIGHT_CTRL_PRESSED |
       LEFT_CTRL_PRESSED |
       SHIFT_PRESSED;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Term::ReadKey : #!/usr/bin/env perl use warnings; use 5.012; use Term::ReadKey; my $key; ReadMode 4;
I have the following directory tree: e:\powershell\services\This-Script-Here-Should-Call-Press any key to continue.ps1 e:\powershell\utils\Press any key
Press any key to continue... appeared after any program/script termination in the screen program.
How can I catch a shift - some-key combination with this script? When I
when we press a key and keep pressing it the keypress and keydown event
I want to simulate many key press events. I found a solution by using
I want to code a key press event to a text box to accept
I want to disable a particular key press in .NET(both VB.NET & C#.NET).``
The Problem I want to press a key when I have a line highlighted
When I click menu strip and then press shortcut key it works but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.