Changeset 98370 in vbox
- Timestamp:
- Jan 31, 2023 5:54:46 PM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 155612
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
r98369 r98370 2906 2906 } 2907 2907 2908 #if defined(RT_OS_DARWIN) || defined(RT_OS_OS2)2909 /**2910 * Fallback keycode conversion using SDL symbols.2911 *2912 * This is used to catch keycodes that's missing from the translation table.2913 *2914 * @returns XT scancode2915 * @param ev SDL scancode2916 */2917 static uint16_t Keyevent2KeycodeFallback(const SDL_KeyboardEvent *ev)2918 {2919 const SDLKey sym = ev->keysym.sym;2920 Log(("SDL key event: sym=%d scancode=%#x unicode=%#x\n",2921 sym, ev->keysym.scancode, ev->keysym.unicode));2922 switch (sym)2923 { /* set 1 scan code */2924 case SDLK_ESCAPE: return 0x01;2925 case SDLK_EXCLAIM:2926 case SDLK_1: return 0x02;2927 case SDLK_AT:2928 case SDLK_2: return 0x03;2929 case SDLK_HASH:2930 case SDLK_3: return 0x04;2931 case SDLK_DOLLAR:2932 case SDLK_4: return 0x05;2933 /* % */2934 case SDLK_5: return 0x06;2935 case SDLK_CARET:2936 case SDLK_6: return 0x07;2937 case SDLK_AMPERSAND:2938 case SDLK_7: return 0x08;2939 case SDLK_ASTERISK:2940 case SDLK_8: return 0x09;2941 case SDLK_LEFTPAREN:2942 case SDLK_9: return 0x0a;2943 case SDLK_RIGHTPAREN:2944 case SDLK_0: return 0x0b;2945 case SDLK_UNDERSCORE:2946 case SDLK_MINUS: return 0x0c;2947 case SDLK_EQUALS:2948 case SDLK_PLUS: return 0x0d;2949 case SDLK_BACKSPACE: return 0x0e;2950 case SDLK_TAB: return 0x0f;2951 case SDLK_q: return 0x10;2952 case SDLK_w: return 0x11;2953 case SDLK_e: return 0x12;2954 case SDLK_r: return 0x13;2955 case SDLK_t: return 0x14;2956 case SDLK_y: return 0x15;2957 case SDLK_u: return 0x16;2958 case SDLK_i: return 0x17;2959 case SDLK_o: return 0x18;2960 case SDLK_p: return 0x19;2961 case SDLK_LEFTBRACKET: return 0x1a;2962 case SDLK_RIGHTBRACKET: return 0x1b;2963 case SDLK_RETURN: return 0x1c;2964 case SDLK_KP_ENTER: return 0x1c | 0x100;2965 case SDLK_LCTRL: return 0x1d;2966 case SDLK_RCTRL: return 0x1d | 0x100;2967 case SDLK_a: return 0x1e;2968 case SDLK_s: return 0x1f;2969 case SDLK_d: return 0x20;2970 case SDLK_f: return 0x21;2971 case SDLK_g: return 0x22;2972 case SDLK_h: return 0x23;2973 case SDLK_j: return 0x24;2974 case SDLK_k: return 0x25;2975 case SDLK_l: return 0x26;2976 case SDLK_COLON:2977 case SDLK_SEMICOLON: return 0x27;2978 case SDLK_QUOTEDBL:2979 case SDLK_QUOTE: return 0x28;2980 case SDLK_BACKQUOTE: return 0x29;2981 case SDLK_LSHIFT: return 0x2a;2982 case SDLK_BACKSLASH: return 0x2b;2983 case SDLK_z: return 0x2c;2984 case SDLK_x: return 0x2d;2985 case SDLK_c: return 0x2e;2986 case SDLK_v: return 0x2f;2987 case SDLK_b: return 0x30;2988 case SDLK_n: return 0x31;2989 case SDLK_m: return 0x32;2990 case SDLK_LESS:2991 case SDLK_COMMA: return 0x33;2992 case SDLK_GREATER:2993 case SDLK_PERIOD: return 0x34;2994 case SDLK_KP_DIVIDE: /*??*/2995 case SDLK_QUESTION:2996 case SDLK_SLASH: return 0x35;2997 case SDLK_RSHIFT: return 0x36;2998 case SDLK_KP_MULTIPLY:2999 case SDLK_PRINT: return 0x37; /* fixme */3000 case SDLK_LALT: return 0x38;3001 case SDLK_MODE: /* alt gr*/3002 case SDLK_RALT: return 0x38 | 0x100;3003 case SDLK_SPACE: return 0x39;3004 case SDLK_CAPSLOCK: return 0x3a;3005 case SDLK_F1: return 0x3b;3006 case SDLK_F2: return 0x3c;3007 case SDLK_F3: return 0x3d;3008 case SDLK_F4: return 0x3e;3009 case SDLK_F5: return 0x3f;3010 case SDLK_F6: return 0x40;3011 case SDLK_F7: return 0x41;3012 case SDLK_F8: return 0x42;3013 case SDLK_F9: return 0x43;3014 case SDLK_F10: return 0x44;3015 case SDLK_PAUSE: return 0x45; /* not right */3016 case SDLK_NUMLOCK: return 0x45;3017 case SDLK_SCROLLOCK: return 0x46;3018 case SDLK_KP7: return 0x47;3019 case SDLK_HOME: return 0x47 | 0x100;3020 case SDLK_KP8: return 0x48;3021 case SDLK_UP: return 0x48 | 0x100;3022 case SDLK_KP9: return 0x49;3023 case SDLK_PAGEUP: return 0x49 | 0x100;3024 case SDLK_KP_MINUS: return 0x4a;3025 case SDLK_KP4: return 0x4b;3026 case SDLK_LEFT: return 0x4b | 0x100;3027 case SDLK_KP5: return 0x4c;3028 case SDLK_KP6: return 0x4d;3029 case SDLK_RIGHT: return 0x4d | 0x100;3030 case SDLK_KP_PLUS: return 0x4e;3031 case SDLK_KP1: return 0x4f;3032 case SDLK_END: return 0x4f | 0x100;3033 case SDLK_KP2: return 0x50;3034 case SDLK_DOWN: return 0x50 | 0x100;3035 case SDLK_KP3: return 0x51;3036 case SDLK_PAGEDOWN: return 0x51 | 0x100;3037 case SDLK_KP0: return 0x52;3038 case SDLK_INSERT: return 0x52 | 0x100;3039 case SDLK_KP_PERIOD: return 0x53;3040 case SDLK_DELETE: return 0x53 | 0x100;3041 case SDLK_SYSREQ: return 0x54;3042 case SDLK_F11: return 0x57;3043 case SDLK_F12: return 0x58;3044 case SDLK_F13: return 0x5b;3045 case SDLK_LMETA:3046 case SDLK_LSUPER: return 0x5b | 0x100;3047 case SDLK_F14: return 0x5c;3048 case SDLK_RMETA:3049 case SDLK_RSUPER: return 0x5c | 0x100;3050 case SDLK_F15: return 0x5d;3051 case SDLK_MENU: return 0x5d | 0x100;3052 #if 03053 case SDLK_CLEAR: return 0x;3054 case SDLK_KP_EQUALS: return 0x;3055 case SDLK_COMPOSE: return 0x;3056 case SDLK_HELP: return 0x;3057 case SDLK_BREAK: return 0x;3058 case SDLK_POWER: return 0x;3059 case SDLK_EURO: return 0x;3060 case SDLK_UNDO: return 0x;3061 #endif3062 default:3063 Log(("Unhandled sdl key event: sym=%d scancode=%#x unicode=%#x\n",3064 ev->keysym.sym, ev->keysym.scancode, ev->keysym.unicode));3065 return 0;3066 }3067 }3068 #endif /* RT_OS_DARWIN */3069 3070 /**3071 * Converts an SDL keyboard eventcode to a XT scancode.3072 *3073 * @returns XT scancode3074 * @param ev SDL scancode3075 */3076 static uint16_t Keyevent2Keycode(const SDL_KeyboardEvent *ev)3077 {3078 // start with the scancode determined by SDL3079 int keycode = ev->keysym.scancode;3080 3081 #ifdef VBOXSDL_WITH_X113082 switch (ev->keysym.sym)3083 {3084 case SDLK_ESCAPE: return 0x01;3085 case SDLK_EXCLAIM:3086 case SDLK_1: return 0x02;3087 case SDLK_AT:3088 case SDLK_2: return 0x03;3089 case SDLK_HASH:3090 case SDLK_3: return 0x04;3091 case SDLK_DOLLAR:3092 case SDLK_4: return 0x05;3093 /* % */3094 case SDLK_5: return 0x06;3095 case SDLK_CARET:3096 case SDLK_6: return 0x07;3097 case SDLK_AMPERSAND:3098 case SDLK_7: return 0x08;3099 case SDLK_ASTERISK:3100 case SDLK_8: return 0x09;3101 case SDLK_LEFTPAREN:3102 case SDLK_9: return 0x0a;3103 case SDLK_RIGHTPAREN:3104 case SDLK_0: return 0x0b;3105 case SDLK_UNDERSCORE:3106 case SDLK_MINUS: return 0x0c;3107 case SDLK_PLUS: return 0x0d;3108 case SDLK_BACKSPACE: return 0x0e;3109 case SDLK_TAB: return 0x0f;3110 case SDLK_q: return 0x10;3111 case SDLK_w: return 0x11;3112 case SDLK_e: return 0x12;3113 case SDLK_r: return 0x13;3114 case SDLK_t: return 0x14;3115 case SDLK_y: return 0x15;3116 case SDLK_u: return 0x16;3117 case SDLK_i: return 0x17;3118 case SDLK_o: return 0x18;3119 case SDLK_p: return 0x19;3120 case SDLK_RETURN: return 0x1c;3121 case SDLK_KP_ENTER: return 0x1c | 0x100;3122 case SDLK_LCTRL: return 0x1d;3123 case SDLK_RCTRL: return 0x1d | 0x100;3124 case SDLK_a: return 0x1e;3125 case SDLK_s: return 0x1f;3126 case SDLK_d: return 0x20;3127 case SDLK_f: return 0x21;3128 case SDLK_g: return 0x22;3129 case SDLK_h: return 0x23;3130 case SDLK_j: return 0x24;3131 case SDLK_k: return 0x25;3132 case SDLK_l: return 0x26;3133 case SDLK_COLON: return 0x27;3134 case SDLK_QUOTEDBL:3135 case SDLK_QUOTE: return 0x28;3136 case SDLK_BACKQUOTE: return 0x29;3137 case SDLK_LSHIFT: return 0x2a;3138 case SDLK_z: return 0x2c;3139 case SDLK_x: return 0x2d;3140 case SDLK_c: return 0x2e;3141 case SDLK_v: return 0x2f;3142 case SDLK_b: return 0x30;3143 case SDLK_n: return 0x31;3144 case SDLK_m: return 0x32;3145 case SDLK_LESS: return 0x33;3146 case SDLK_GREATER: return 0x34;3147 case SDLK_KP_DIVIDE: /*??*/3148 case SDLK_QUESTION: return 0x35;3149 case SDLK_RSHIFT: return 0x36;3150 case SDLK_KP_MULTIPLY:3151 //case SDLK_PRINT: return 0x37; /* fixme */3152 case SDLK_LALT: return 0x38;3153 case SDLK_MODE: /* alt gr*/3154 case SDLK_RALT: return 0x38 | 0x100;3155 case SDLK_SPACE: return 0x39;3156 case SDLK_CAPSLOCK: return 0x3a;3157 case SDLK_F1: return 0x3b;3158 case SDLK_F2: return 0x3c;3159 case SDLK_F3: return 0x3d;3160 case SDLK_F4: return 0x3e;3161 case SDLK_F5: return 0x3f;3162 case SDLK_F6: return 0x40;3163 case SDLK_F7: return 0x41;3164 case SDLK_F8: return 0x42;3165 case SDLK_F9: return 0x43;3166 case SDLK_F10: return 0x44;3167 case SDLK_PAUSE: return 0x45; /* not right */3168 //case SDLK_NUMLOCK: return 0x45;3169 //case SDLK_SCROLLOCK: return 0x46;3170 //case SDLK_KP7: return 0x47;3171 case SDLK_HOME: return 0x47 | 0x100;3172 //case SDLK_KP8: return 0x48;3173 case SDLK_UP: return 0x48 | 0x100;3174 //case SDLK_KP9: return 0x49;3175 case SDLK_PAGEUP: return 0x49 | 0x100;3176 case SDLK_KP_MINUS: return 0x4a;3177 //case SDLK_KP4: return 0x4b;3178 case SDLK_LEFT: return 0x4b | 0x100;3179 //case SDLK_KP5: return 0x4c;3180 //case SDLK_KP6: return 0x4d;3181 case SDLK_RIGHT: return 0x4d | 0x100;3182 case SDLK_KP_PLUS: return 0x4e;3183 //case SDLK_KP1: return 0x4f;3184 case SDLK_END: return 0x4f | 0x100;3185 //case SDLK_KP2: return 0x50;3186 case SDLK_DOWN: return 0x50 | 0x100;3187 //case SDLK_KP3: return 0x51;3188 case SDLK_PAGEDOWN: return 0x51 | 0x100;3189 //case SDLK_KP0: return 0x52;3190 case SDLK_INSERT: return 0x52 | 0x100;3191 case SDLK_KP_PERIOD: return 0x53;3192 case SDLK_DELETE: return 0x53 | 0x100;3193 case SDLK_SYSREQ: return 0x54;3194 case SDLK_F11: return 0x57;3195 case SDLK_F12: return 0x58;3196 case SDLK_F13: return 0x5b;3197 case SDLK_F14: return 0x5c;3198 case SDLK_F15: return 0x5d;3199 case SDLK_MENU: return 0x5d | 0x100;3200 default:3201 return 0;3202 }3203 #elif defined(RT_OS_DARWIN)3204 /* This is derived partially from SDL_QuartzKeys.h and partially from testing. */3205 static const uint16_t s_aMacToSet1[] =3206 {3207 /* set-1 SDL_QuartzKeys.h */3208 0x1e, /* QZ_a 0x00 */3209 0x1f, /* QZ_s 0x01 */3210 0x20, /* QZ_d 0x02 */3211 0x21, /* QZ_f 0x03 */3212 0x23, /* QZ_h 0x04 */3213 0x22, /* QZ_g 0x05 */3214 0x2c, /* QZ_z 0x06 */3215 0x2d, /* QZ_x 0x07 */3216 0x2e, /* QZ_c 0x08 */3217 0x2f, /* QZ_v 0x09 */3218 0x56, /* between lshift and z. 'INT 1'? */3219 0x30, /* QZ_b 0x0B */3220 0x10, /* QZ_q 0x0C */3221 0x11, /* QZ_w 0x0D */3222 0x12, /* QZ_e 0x0E */3223 0x13, /* QZ_r 0x0F */3224 0x15, /* QZ_y 0x10 */3225 0x14, /* QZ_t 0x11 */3226 0x02, /* QZ_1 0x12 */3227 0x03, /* QZ_2 0x13 */3228 0x04, /* QZ_3 0x14 */3229 0x05, /* QZ_4 0x15 */3230 0x07, /* QZ_6 0x16 */3231 0x06, /* QZ_5 0x17 */3232 0x0d, /* QZ_EQUALS 0x18 */3233 0x0a, /* QZ_9 0x19 */3234 0x08, /* QZ_7 0x1A */3235 0x0c, /* QZ_MINUS 0x1B */3236 0x09, /* QZ_8 0x1C */3237 0x0b, /* QZ_0 0x1D */3238 0x1b, /* QZ_RIGHTBRACKET 0x1E */3239 0x18, /* QZ_o 0x1F */3240 0x16, /* QZ_u 0x20 */3241 0x1a, /* QZ_LEFTBRACKET 0x21 */3242 0x17, /* QZ_i 0x22 */3243 0x19, /* QZ_p 0x23 */3244 0x1c, /* QZ_RETURN 0x24 */3245 0x26, /* QZ_l 0x25 */3246 0x24, /* QZ_j 0x26 */3247 0x28, /* QZ_QUOTE 0x27 */3248 0x25, /* QZ_k 0x28 */3249 0x27, /* QZ_SEMICOLON 0x29 */3250 0x2b, /* QZ_BACKSLASH 0x2A */3251 0x33, /* QZ_COMMA 0x2B */3252 0x35, /* QZ_SLASH 0x2C */3253 0x31, /* QZ_n 0x2D */3254 0x32, /* QZ_m 0x2E */3255 0x34, /* QZ_PERIOD 0x2F */3256 0x0f, /* QZ_TAB 0x30 */3257 0x39, /* QZ_SPACE 0x31 */3258 0x29, /* QZ_BACKQUOTE 0x32 */3259 0x0e, /* QZ_BACKSPACE 0x33 */3260 0x9c, /* QZ_IBOOK_ENTER 0x34 */3261 0x01, /* QZ_ESCAPE 0x35 */3262 0x5c|0x100, /* QZ_RMETA 0x36 */3263 0x5b|0x100, /* QZ_LMETA 0x37 */3264 0x2a, /* QZ_LSHIFT 0x38 */3265 0x3a, /* QZ_CAPSLOCK 0x39 */3266 0x38, /* QZ_LALT 0x3A */3267 0x1d, /* QZ_LCTRL 0x3B */3268 0x36, /* QZ_RSHIFT 0x3C */3269 0x38|0x100, /* QZ_RALT 0x3D */3270 0x1d|0x100, /* QZ_RCTRL 0x3E */3271 0, /* */3272 0, /* */3273 0x53, /* QZ_KP_PERIOD 0x41 */3274 0, /* */3275 0x37, /* QZ_KP_MULTIPLY 0x43 */3276 0, /* */3277 0x4e, /* QZ_KP_PLUS 0x45 */3278 0, /* */3279 0x45, /* QZ_NUMLOCK 0x47 */3280 0, /* */3281 0, /* */3282 0, /* */3283 0x35|0x100, /* QZ_KP_DIVIDE 0x4B */3284 0x1c|0x100, /* QZ_KP_ENTER 0x4C */3285 0, /* */3286 0x4a, /* QZ_KP_MINUS 0x4E */3287 0, /* */3288 0, /* */3289 0x0d/*?*/, /* QZ_KP_EQUALS 0x51 */3290 0x52, /* QZ_KP0 0x52 */3291 0x4f, /* QZ_KP1 0x53 */3292 0x50, /* QZ_KP2 0x54 */3293 0x51, /* QZ_KP3 0x55 */3294 0x4b, /* QZ_KP4 0x56 */3295 0x4c, /* QZ_KP5 0x57 */3296 0x4d, /* QZ_KP6 0x58 */3297 0x47, /* QZ_KP7 0x59 */3298 0, /* */3299 0x48, /* QZ_KP8 0x5B */3300 0x49, /* QZ_KP9 0x5C */3301 0, /* */3302 0, /* */3303 0, /* */3304 0x3f, /* QZ_F5 0x60 */3305 0x40, /* QZ_F6 0x61 */3306 0x41, /* QZ_F7 0x62 */3307 0x3d, /* QZ_F3 0x63 */3308 0x42, /* QZ_F8 0x64 */3309 0x43, /* QZ_F9 0x65 */3310 0, /* */3311 0x57, /* QZ_F11 0x67 */3312 0, /* */3313 0x37|0x100, /* QZ_PRINT / F13 0x69 */3314 0x63, /* QZ_F16 0x6A */3315 0x46, /* QZ_SCROLLOCK 0x6B */3316 0, /* */3317 0x44, /* QZ_F10 0x6D */3318 0x5d|0x100, /* */3319 0x58, /* QZ_F12 0x6F */3320 0, /* */3321 0/* 0xe1,0x1d,0x45*/, /* QZ_PAUSE 0x71 */3322 0x52|0x100, /* QZ_INSERT / HELP 0x72 */3323 0x47|0x100, /* QZ_HOME 0x73 */3324 0x49|0x100, /* QZ_PAGEUP 0x74 */3325 0x53|0x100, /* QZ_DELETE 0x75 */3326 0x3e, /* QZ_F4 0x76 */3327 0x4f|0x100, /* QZ_END 0x77 */3328 0x3c, /* QZ_F2 0x78 */3329 0x51|0x100, /* QZ_PAGEDOWN 0x79 */3330 0x3b, /* QZ_F1 0x7A */3331 0x4b|0x100, /* QZ_LEFT 0x7B */3332 0x4d|0x100, /* QZ_RIGHT 0x7C */3333 0x50|0x100, /* QZ_DOWN 0x7D */3334 0x48|0x100, /* QZ_UP 0x7E */3335 0x5e|0x100, /* QZ_POWER 0x7F */ /* have different break key! */3336 };3337 3338 if (keycode == 0)3339 {3340 /* This could be a modifier or it could be 'a'. */3341 switch (ev->keysym.sym)3342 {3343 case SDLK_LSHIFT: keycode = 0x2a; break;3344 case SDLK_RSHIFT: keycode = 0x36; break;3345 case SDLK_LCTRL: keycode = 0x1d; break;3346 case SDLK_RCTRL: keycode = 0x1d | 0x100; break;3347 case SDLK_LALT: keycode = 0x38; break;3348 case SDLK_MODE: /* alt gr */3349 case SDLK_RALT: keycode = 0x38 | 0x100; break;3350 case SDLK_RMETA:3351 case SDLK_RSUPER: keycode = 0x5c | 0x100; break;3352 case SDLK_LMETA:3353 case SDLK_LSUPER: keycode = 0x5b | 0x100; break;3354 /* Assumes normal key. */3355 default: keycode = s_aMacToSet1[keycode]; break;3356 }3357 }3358 else3359 {3360 if ((unsigned)keycode < RT_ELEMENTS(s_aMacToSet1))3361 keycode = s_aMacToSet1[keycode];3362 else3363 keycode = 0;3364 if (!keycode)3365 {3366 # ifdef DEBUG_bird3367 RTPrintf("Untranslated: keycode=%#x (%d)\n", keycode, keycode);3368 # endif3369 keycode = Keyevent2KeycodeFallback(ev);3370 }3371 }3372 # ifdef DEBUG_bird3373 RTPrintf("scancode=%#x -> %#x\n", ev->keysym.scancode, keycode);3374 # endif3375 3376 #elif defined(RT_OS_OS2)3377 keycode = Keyevent2KeycodeFallback(ev);3378 #endif /* RT_OS_DARWIN */3379 return keycode;3380 }3381 2908 3382 2909 /** … … 3409 2936 static void ProcessKey(SDL_KeyboardEvent *ev) 3410 2937 { 3411 #if 0 //(defined(DEBUG) || defined(VBOX_WITH_STATISTICS)) && !defined(VBOX_WITH_SDL2) 3412 if (gpMachineDebugger && ev->type == SDL_KEYDOWN) 3413 { 3414 // first handle the debugger hotkeys 3415 uint8_t *keystate = SDL_GetKeyState(NULL); 3416 #if 0 3417 // CTRL+ALT+Fn is not free on Linux hosts with Xorg .. 3418 if (keystate[SDLK_LALT] && !keystate[SDLK_LCTRL]) 3419 #else 3420 if (keystate[SDLK_LALT] && keystate[SDLK_LCTRL]) 3421 #endif 3422 { 3423 switch (ev->keysym.sym) 3424 { 3425 // pressing CTRL+ALT+F11 dumps the statistics counter 3426 case SDLK_F12: 3427 RTPrintf("ResetStats\n"); /* Visual feedback in console window */ 3428 gpMachineDebugger->ResetStats(NULL); 3429 break; 3430 // pressing CTRL+ALT+F12 resets all statistics counter 3431 case SDLK_F11: 3432 gpMachineDebugger->DumpStats(NULL); 3433 RTPrintf("DumpStats\n"); /* Vistual feedback in console window */ 3434 break; 3435 default: 3436 break; 3437 } 3438 } 3439 #if 1 3440 else if (keystate[SDLK_LALT] && !keystate[SDLK_LCTRL]) 3441 { 3442 switch (ev->keysym.sym) 3443 { 3444 // pressing Alt-F8 toggles singlestepping mode 3445 case SDLK_F8: 3446 { 3447 BOOL singlestepEnabled; 3448 gpMachineDebugger->COMGETTER(SingleStep)(&singlestepEnabled); 3449 gpMachineDebugger->COMSETTER(SingleStep)(!singlestepEnabled); 3450 break; 3451 } 3452 default: 3453 break; 3454 } 3455 } 3456 #endif 3457 // pressing Ctrl-F12 toggles the logger 3458 else if ((keystate[SDLK_RCTRL] || keystate[SDLK_LCTRL]) && ev->keysym.sym == SDLK_F12) 3459 { 3460 BOOL logEnabled = TRUE; 3461 gpMachineDebugger->COMGETTER(LogEnabled)(&logEnabled); 3462 gpMachineDebugger->COMSETTER(LogEnabled)(!logEnabled); 3463 #ifdef DEBUG_bird 3464 return; 3465 #endif 3466 } 3467 // pressing F12 sets a logmark 3468 else if (ev->keysym.sym == SDLK_F12) 3469 { 3470 RTLogPrintf("****** LOGGING MARK ******\n"); 3471 RTLogFlush(NULL); 3472 } 3473 // now update the titlebar flags 3474 UpdateTitlebar(TITLEBAR_NORMAL); 3475 } 3476 #endif // DEBUG || VBOX_WITH_STATISTICS 3477 3478 // the pause key is the weirdest, needs special handling 3479 if (ev->keysym.sym == SDLK_PAUSE) 3480 { 3481 int v = 0; 3482 if (ev->type == SDL_KEYUP) 3483 v |= 0x80; 3484 gpKeyboard->PutScancode(0xe1); 3485 gpKeyboard->PutScancode(0x1d | v); 3486 gpKeyboard->PutScancode(0x45 | v); 3487 return; 3488 } 3489 3490 /* 3491 * Perform SDL key event to scancode conversion 3492 */ 3493 int keycode = Keyevent2Keycode(ev); 3494 3495 switch(keycode) 3496 { 3497 case 0x00: 3498 { 3499 /* sent when leaving window: reset the modifiers state */ 3500 ResetKeys(); 3501 return; 3502 } 3503 3504 case 0x2a: /* Left Shift */ 3505 case 0x36: /* Right Shift */ 3506 case 0x1d: /* Left CTRL */ 3507 case 0x1d|0x100: /* Right CTRL */ 3508 case 0x38: /* Left ALT */ 3509 case 0x38|0x100: /* Right ALT */ 3510 { 3511 if (ev->type == SDL_KEYUP) 3512 gaModifiersState[keycode & ~0x100] = 0; 3513 else 3514 gaModifiersState[keycode & ~0x100] = 1; 3515 break; 3516 } 3517 3518 case 0x45: /* Num Lock */ 3519 case 0x3a: /* Caps Lock */ 3520 { 3521 /* 3522 * SDL generates a KEYDOWN event if the lock key is active and a KEYUP event 3523 * if the lock key is inactive. See SDL_DISABLE_LOCK_KEYS. 3524 */ 3525 if (ev->type == SDL_KEYDOWN || ev->type == SDL_KEYUP) 3526 { 3527 gpKeyboard->PutScancode(keycode); 3528 gpKeyboard->PutScancode(keycode | 0x80); 3529 } 3530 return; 3531 } 3532 } 3533 3534 if (ev->type != SDL_KEYDOWN) 3535 { 3536 /* 3537 * Some keyboards (e.g. the one of mine T60) don't send a NumLock scan code on every 3538 * press of the key. Both the guest and the host should agree on the NumLock state. 3539 * If they differ, we try to alter the guest NumLock state by sending the NumLock key 3540 * scancode. We will get a feedback through the KBD_CMD_SET_LEDS command if the guest 3541 * tries to set/clear the NumLock LED. If a (silly) guest doesn't change the LED, don't 3542 * bother him with NumLock scancodes. At least our BIOS, Linux and Windows handle the 3543 * NumLock LED well. 3544 */ 3545 if ( gcGuestNumLockAdaptions 3546 && (gfGuestNumLockPressed ^ !!(SDL_GetModState() & KMOD_NUM))) 3547 { 3548 gcGuestNumLockAdaptions--; 3549 gpKeyboard->PutScancode(0x45); 3550 gpKeyboard->PutScancode(0x45 | 0x80); 3551 } 3552 if ( gcGuestCapsLockAdaptions 3553 && (gfGuestCapsLockPressed ^ !!(SDL_GetModState() & KMOD_CAPS))) 3554 { 3555 gcGuestCapsLockAdaptions--; 3556 gpKeyboard->PutScancode(0x3a); 3557 gpKeyboard->PutScancode(0x3a | 0x80); 3558 } 3559 } 3560 3561 /* 3562 * Now we send the event. Apply extended and release prefixes. 3563 */ 3564 #ifdef RT_OS_WINDOWS 2938 /* According to SDL2/SDL_scancodes.h ev->keysym.sym stores scancodes which are 2939 * based on USB usage page standard. This is what we can directly pass to 2940 * IKeyboard::putUsageCode. */ 3565 2941 gpKeyboard->PutUsageCode(SDL_GetScancodeFromKey(ev->keysym.sym), 0x07, ev->type == SDL_KEYUP ? TRUE : FALSE); 3566 #else3567 if (keycode & 0x100)3568 gpKeyboard->PutScancode(0xe0);3569 3570 gpKeyboard->PutScancode(ev->type == SDL_KEYUP ? (keycode & 0x7f) | 0x803571 : (keycode & 0x7f));3572 #endif /* RT_OS_WINDOWS */3573 2942 } 3574 2943 … … 4592 3961 { 4593 3962 // /* send Ctrl-Alt-Fx to guest */ 3963 #if 0 // Fix me. I was not working with PutScancodes API. Need to find the corect way to do this with PutUsagecode API 4594 3964 com::SafeArray<LONG> keys(6); 4595 3965 … … 4602 3972 4603 3973 gpKeyboard->PutScancodes(ComSafeArrayAsInParam(keys), NULL); 3974 #endif 4604 3975 return VINF_SUCCESS; 4605 3976 }
Note:
See TracChangeset
for help on using the changeset viewer.