From: Robert M. <rm...@po...> - 2007-01-19 20:51:29
|
Waldemar Biernacki wrote: > I think that in Win32::GUI there is a bug. I don't :-) I think you are missing some of the subtleties of windows GUI programming. > When you start the code attached at the end of the mail then you can see > that: > > 1. key F10 does not work. The same is in WinXP and in Win98. That depends what you mean by 'does not work'. F10 is a system-wide accelerator, used to move focus to the menu bar of a window. It never generates a WM_KEYDOWN message (which is what -onKeyDown hooks), but generates WM_SYSKEYDOWN message instead. Alt does the same, as does any Alt+CHAR. > 2. When I did similar program for Win32-Console package it work correctly. The Console and Windows subsystems are very different when it comes to processing key strokes. > 3. The F10 key behavior is funny: it works as a switcher for other Fxx > keys but not for other keys. After pressing F10, when you press a letter key don't you get a beep the first time, and then all keys start working again? > When I press the F10 key 1,3,... (odd number) times then other Fxx keys > don't work. If you add a menu to the window, I think it becomes a bit more obvious (code below). Watch the focus move the the menu bar when you press and release the F10 key. > ----------- > It could seem that it is not important problem. In the case of WinXP the > problem is not big in fact. > Only F10 doesn't work and application works smoothly. > However on Windows98 there is quite serious problem; because the > keyboard answer > is unstable and unpredictible I am facing against the problem: > Is the problem of Windows or Perl itself? If you are referring to the Alt+_F4 problem in your previous mail, then I think it is a Win98 problem. Regards, Rob. #!perl -w use strict; use warnings; use Win32::GUI qw(VK_SHIFT VK_CONTROL VK_MENU); my $menu = Win32::GUI::Menu->new( "File" => "File", ">Exit" => { -name => "Exit", -onClick => sub {-1}, }, ); my $Window = new Win32::GUI::Window ( -size => [200,100], -onKeyDown => \&keydown, -menu => $menu, ); $Window->Show(); Win32::GUI::Dialog(); $Window->Hide(); exit(1); #----------------------------------------- sub keydown { my ($self, $ext, $vkey) = @_; # I'm not interested in seeing the modifier # keys on thier own: return 1 if($vkey == VK_SHIFT or $vkey == VK_CONTROL or $vkey == VK_MENU); print "(virtual) key just pressed: $vkey (" . decode_vk($vkey) . ")\n"; my $modifiers = ""; $modifiers .= "Shift, " if Win32::GUI::GetKeyState(VK_SHIFT); $modifiers .= "Alt, " if Win32::GUI::GetKeyState(VK_MENU); $modifiers .= "Ctrl, " if Win32::GUI::GetKeyState(VK_CONTROL); $modifiers = substr $modifiers, 0, -2; print "modifiers: $modifiers\n"; my $kbd_ref = Win32::GUI::GetKeyboardState(); my $wanted = ""; my $count = 0; for (0 .. 255) { if ($kbd_ref->[$_]) { $wanted .= "$_(".decode_vk($_).")|" ; ++$count; } } $wanted = substr $wanted, 0, -1; print "$count depressed (virtual) keys: $wanted\n\n"; return 1; } #----------------------------------------- my %vk_to_string; sub decode_vk { return $vk_to_string{shift()}; } BEGIN { %vk_to_string = ( 1 => "VK_LBUTTON", 2 => "VK_RBUTTON", 3 => "VK_CANCEL", 4 => "VK_MBUTTON", 5 => "VK_XBUTTON1", 6 => "VK_XBUTTON2", 8 => "VK_BACK", 9 => "VK_TAB", 12 => "VK_CLEAR", 13 => "VK_RETURN", 16 => "VK_SHIFT", 17 => "VK_CONTROL", 18 => "VK_MENU", 19 => "VK_PAUSE", 20 => "VK_CAPITAL", 21 => "VK_HANGEUL", 23 => "VK_JUNJA", 24 => "VK_FINAL", 25 => "VK_KANJI", 27 => "VK_ESCAPE", 28 => "VK_CONVERT", 29 => "VK_NONCONVERT", 30 => "VK_ACCEPT", 31 => "VK_MODECHANGE", 32 => "VK_SPACE", 33 => "VK_PRIOR", 34 => "VK_NEXT", 35 => "VK_END", 36 => "VK_HOME", 37 => "VK_LEFT", 38 => "VK_UP", 39 => "VK_RIGHT", 40 => "VK_DOWN", 41 => "VK_SELECT", 42 => "VK_PRINT", 43 => "VK_EXECUTE", 44 => "VK_SNAPSHOT", 45 => "VK_INSERT", 46 => "VK_DELETE", 47 => "VK_HELP", 48 => "VK_0", 49 => "VK_1", 50 => "VK_2", 51 => "VK_3", 52 => "VK_4", 53 => "VK_5", 54 => "VK_6", 55 => "VK_7", 56 => "VK_8", 57 => "VK_9", 65 => "VK_A", 66 => "VK_B", 67 => "VK_C", 68 => "VK_D", 69 => "VK_E", 70 => "VK_F", 71 => "VK_G", 72 => "VK_H", 73 => "VK_I", 74 => "VK_J", 75 => "VK_K", 76 => "VK_L", 77 => "VK_M", 78 => "VK_N", 79 => "VK_O", 80 => "VK_P", 81 => "VK_Q", 82 => "VK_R", 83 => "VK_S", 84 => "VK_T", 85 => "VK_U", 86 => "VK_V", 87 => "VK_W", 88 => "VK_X", 89 => "VK_Y", 90 => "VK_Z", 91 => "VK_LWIN", 92 => "VK_RWIN", 93 => "VK_APPS", 95 => "VK_SLEEP", 96 => "VK_NUMPAD0", 97 => "VK_NUMPAD1", 98 => "VK_NUMPAD2", 99 => "VK_NUMPAD3", 100 => "VK_NUMPAD4", 101 => "VK_NUMPAD5", 102 => "VK_NUMPAD6", 103 => "VK_NUMPAD7", 104 => "VK_NUMPAD8", 105 => "VK_NUMPAD9", 106 => "VK_MULTIPLY", 107 => "VK_ADD", 108 => "VK_SEPARATOR", 109 => "VK_SUBTRACT", 110 => "VK_DECIMAL", 111 => "VK_DIVIDE", 112 => "VK_F1", 113 => "VK_F2", 114 => "VK_F3", 115 => "VK_F4", 116 => "VK_F5", 117 => "VK_F6", 118 => "VK_F7", 119 => "VK_F8", 120 => "VK_F9", 121 => "VK_F10", 122 => "VK_F11", 123 => "VK_F12", 124 => "VK_F13", 125 => "VK_F14", 126 => "VK_F15", 127 => "VK_F16", 128 => "VK_F17", 129 => "VK_F18", 130 => "VK_F19", 131 => "VK_F20", 132 => "VK_F21", 133 => "VK_F22", 134 => "VK_F23", 135 => "VK_F24", 144 => "VK_NUMLOCK", 145 => "VK_SCROLL", 146 => "VK_OEM_FJ_JISHO", 147 => "VK_OEM_FJ_MASSHOU", 148 => "VK_OEM_FJ_TOUROKU", 149 => "VK_OEM_FJ_LOYA", 150 => "VK_OEM_FJ_ROYA", 160 => "VK_LSHIFT", 161 => "VK_RSHIFT", 162 => "VK_LCONTROL", 163 => "VK_RCONTROL", 164 => "VK_LMENU", 165 => "VK_RMENU", 166 => "VK_BROWSER_BACK", 167 => "VK_BROWSER_FORWARD", 168 => "VK_BROWSER_REFRESH", 169 => "VK_BROWSER_STOP", 170 => "VK_BROWSER_SEARCH", 171 => "VK_BROWSER_FAVORITES", 172 => "VK_BROWSER_HOME", 173 => "VK_VOLUME_MUTE", 174 => "VK_VOLUME_DOWN", 175 => "VK_VOLUME_UP", 176 => "VK_MEDIA_NEXT_TRACK", 177 => "VK_MEDIA_PREV_TRACK", 178 => "VK_MEDIA_STOP", 179 => "VK_MEDIA_PLAY_PAUSE", 180 => "VK_LAUNCH_MAIL", 181 => "VK_LAUNCH_MEDIA_SELECT", 182 => "VK_LAUNCH_APP1", 183 => "VK_LAUNCH_APP2", 186 => "VK_OEM_1", 187 => "VK_OEM_PLUS", 188 => "VK_OEM_COMMA", 189 => "VK_OEM_MINUS", 190 => "VK_OEM_PERIOD", 191 => "VK_OEM_2", 192 => "VK_OEM_3", 219 => "VK_OEM_4", 220 => "VK_OEM_5", 221 => "VK_OEM_6", 222 => "VK_OEM_7", 223 => "VK_OEM_8", 225 => "VK_OEM_AX", 226 => "VK_OEM_102", 227 => "VK_ICO_HELP", 228 => "VK_ICO_00", 229 => "VK_PROCESSKEY", 230 => "VK_ICO_CLEAR", 231 => "VK_PACKET", 233 => "VK_OEM_RESET", 234 => "VK_OEM_JUMP", 235 => "VK_OEM_PA1", 236 => "VK_OEM_PA2", 237 => "VK_OEM_PA3", 238 => "VK_OEM_WSCTRL", 239 => "VK_OEM_CUSEL", 240 => "VK_OEM_ATTN", 241 => "VK_OEM_FINISH", 242 => "VK_OEM_COPY", 243 => "VK_OEM_AUTO", 244 => "VK_OEM_ENLW", 245 => "VK_OEM_BACKTAB", 246 => "VK_ATTN", 247 => "VK_CRSEL", 248 => "VK_EXSEL", 249 => "VK_EREOF", 250 => "VK_PLAY", 251 => "VK_ZOOM", 252 => "VK_NONAME", 253 => "VK_PA1", 254 => "VK_OEM_CLEAR", ); } #BEGIN __END__ |