Thanks Jonathan, incredible turn-around time!
I compiled/tested this with visualstudio 9, and it worked* well.
If you want (for clarity), the key codes are available as VK_* in foo.h. Please find below a modified portion of Win32PeekChar.
Also, your email address is out of date in the pod for ReadKey.pm.
Thanks again!
*- Microsoft added run-time parameter checking to all of the exports from the MS Visual C Runtime. If "invalid" parameters are passed to a c-runtime function (like _get_osfhandle), rather than return an error code, the c-runtime by default causes an AV and you get a "this program has stopped working" dialog box. I modified every API entry to call _set_invalid_parameter_handler, and things worked great.
switch(record.EventType)
{
case KEY_EVENT:
/* printf("\nkeyDown = %d, repeat = %d, vKey = %d, vScan = %d, ASCII = %d, Control = %d\n",
record.Event.KeyEvent.bKeyDown,
record.Event.KeyEvent.wRepeatCount,
record.Event.KeyEvent.wVirtualKeyCode,
record.Event.KeyEvent.wVirtualScanCode,
record.Event.KeyEvent.uChar.AsciiChar,
record.Event.KeyEvent.dwControlKeyState); */
if (record.Event.KeyEvent.bKeyDown == FALSE)
goto again; /* throw away KeyUp events */
switch(record.Event.KeyEvent.wVirtualKeyCode) {
case VK_SHIFT: case VK_LSHIFT: case VK_RSHIFT:
case VK_CONTROL: case VK_LCONTROL: case VK_RCONTROL:
case VK_MENU: case VK_LMENU: case VK_RMENU:
case VK_CAPITAL: case VK_NUMLOCK: case VK_SCROLL:
/* throw away shift/alt/ctrl key only key events */
goto again;
case VK_UP: KEY_PUSH3(27, 91, 65);
case VK_DOWN: KEY_PUSH3(27, 91, 66);
case VK_RIGHT: KEY_PUSH3(27, 91, 67);
case VK_LEFT: KEY_PUSH3(27, 91, 68);
case VK_PRIOR: KEY_PUSH3(27, 79, 121);
case VK_NEXT: KEY_PUSH3(27, 79, 115);
case VK_HOME: KEY_PUSH4(27, 91, 49, 126);
case VK_INSERT: KEY_PUSH4(27, 91, 50, 126);
case VK_DELETE: KEY_PUSH4(27, 91, 51, 126);
case VK_END: KEY_PUSH4(27, 91, 52, 126);
}
keyCount = record.Event.KeyEvent.wRepeatCount;
break;
default:
keyCount = 0;
goto again;
break;
}
Show quoted text-----Original Message-----
From: jonathan.stowe@gmail.com [mailto:jonathan.stowe@gmail.com] On Behalf Of Jonathan Stowe
Sent: Wednesday, October 08, 2008 4:19 AM
To: perl5-porters@perl.org; bug-TermReadKey@rt.cpan.org; Jeremy Braun
Subject: Re: [perl #59690][cpan #16538] Term::ReadKey's Win32PeekChar doesn't support special keys
Hi Jeremy,
Term::ReadKey is not maintained as part of the Perl core. The ticket
#59690 can be closed.
I already have an ancient RT ticket (#16538) against this same
feature request with a patch, I've held off releasing this because I
haven't had the facilities to compile and test on Windows.
If someone could volunteer to help test a new release then I'd be
happy to make the fix.
2008/10/7 via RT Jeremy Braun <perlbug-followup@perl.org>:
> # New Ticket Created by Jeremy Braun
> # Please include the string: [perl #59690]
> # in the subject line of all future correspondence about this issue.
> # <URL:
http://rt.perl.org/rt3/Ticket/Display.html?id=59690 >
>
>
> This is a bug report for perl from jerbraun@microsoft.com,
> generated with the help of perlbug 1.36 running under perl 5.10.0.
>
>
> -----------------------------------------------------------------
> [Please enter your report here]
>
> In ReadKey.xs, Win32PeekChar only uses
> record.Event.KeyEvent.uChar.AsciiChar to figure out the *key return
> value. For text this is okay, but special keys (F1-Fx, HOME, PAGEUP,
> PAGEDOWN, ARROWS, etc) all set AsciiChar to zero. In these cases, the
> wVirtualKeyCode must be used to figure out what key was pressed.
>
> (Perl's getc seems to have a similiar bug?)
>
>
> [Please do not change anything below this line]
> -----------------------------------------------------------------
> ---
> Flags:
> category=library
> severity=medium
> ---
> Site configuration information for perl 5.10.0:
>
> Configured by SYSTEM at Tue May 13 16:52:25 2008.
>
> Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
> Platform:
> osname=MSWin32, osvers=5.00, archname=MSWin32-x86-multi-thread
> uname=''
> config_args='undef'
> hint=recommended, useposix=true, d_sigaction=undef
> useithreads=define, usemultiplicity=define
> useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
> use64bitint=undef, use64bitall=undef, uselongdouble=undef
> usemymalloc=n, bincompat5005=undef
> Compiler:
> cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPRIVLIB_LAST_IN_INC -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
> optimize='-MD -Zi -DNDEBUG -O1',
> cppflags='-DWIN32'
> ccversion='14.1.60511', gccversion='', gccosandvers=''
> intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
> d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
> ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksize=8
> alignbytes=8, prototype=define
> Linker and Libraries:
> ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf -libpath:"D:\sd\pyxis\source\40\zune\tools\perl\lib\CORE" -machine:x86'
> libpth=\lib
> libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
> perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
> libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl510.lib
> gnulibc_version=''
> Dynamic Linking:
> dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
> cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf -libpath:"D:\sd\pyxis\source\40\zune\tools\perl\lib\CORE" -machine:x86'
>
> Locally applied patches:
> ACTIVEPERL_LOCAL_PATCHES_ENTRY
> 33741 avoids segfaults invoking S_raise_signal() (on Linux)
> 33763 Win32 process ids can have more than 16 bits
> 32809 Load 'loadable object' with non-default file extension
> 32728 64-bit fix for Time::Local
>
> ---
> @INC for perl 5.10.0:
> D:/sd/pyxis/source/40/zune/tools/perl/site/lib
> D:/sd/pyxis/source/40/zune/tools/perl/lib
> .
>
> ---
> Environment for perl 5.10.0:
> HOME=C:\Users\jerbraun
> LANG (unset)
> LANGUAGE (unset)
> LD_LIBRARY_PATH (unset)
> LOGDIR (unset)
> PATH=D:\sd\pyxis\source\40\sdk\bin\i386\ARM;D:\sd\pyxis\source\40\sdk\bin\i386;D:\sd\pyxis\source\40\public\common\oak\Bin\i386;D:\sd\pyxis\source\40\private\bin\i386;D:\sd\pyxis\source\40\private\bat;D:\sd\pyxis\source\40\public\common\oak\misc;D:\sd\pyxis\source\40\developr\jerbraun;C:\Python25\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;D:\sd\pyxis\source\40\zune\developer\jerbraun\bin;C:\PROGRA~1\NcFTP;C:\Program Files\Microsoft Application Virtualization Client;C:\Program Files\Microsoft Network Monitor 3\;C:\Windows\system32\WindowsPowerShell\v1.0\;D:\sd\pyxis\source\40\platform\WOOKIE;D:\sd\pyxis\source\40\platform\WOOKIE\tools\bin\i386;D:\sd\pyxis\source\40\platform\WOOKIE\tools\nvflash\bin\i386;D:\sd\pyxis\source\40\platform\WOOKIE\tools\buildbct\bin\i386;D:\sd\pyxis\source\40\zune\tools\bin\i386;D:\sd\pyxis\source\40\zune\tools\bat;D:\sd\pyxis\source\40\zune\tools\perl\bin;D:\sd\pyxis\source\40\zune\tools\perl\site\bin;C:\Program Files\GnuWin32\bin
!
> ;c:\Python25;F:\sd\xbox\cadence\tools\bin;D:\sd\pyxis\source\40\zune\tools\env;C:\Cadence\SPB_16.01\tools\specctra\bin;C:\Cadence\SPB_16.01\tools\pcb\bin;C:\Cadence\SPB_16.01\tools\bin;C:\Cadence\SPB_16.01\tools\libutil\bin;C:\Cadence\SPB_16.01\tools\fet\bin
> PERLDOC_NROFF=groff -E -mtty-char -Tascii -P-c
> PERL_BADLANG (unset)
> SHELL (unset)
>