Changeset 963 in vbox for trunk/src/VBox/Frontends/VBoxBFE
- Timestamp:
- Feb 18, 2007 9:08:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxBFE/SDLConsole.cpp
r146 r963 407 407 SDL_PushEvent(&event); 408 408 } 409 410 #if defined(__DARWIN__) 411 /** 412 * Fallback keycode conversion using SDL symbols. 413 * 414 * This is used to catch keycodes that's missing from the translation table. 415 * 416 * @returns XT scancode 417 * @param ev SDL scancode 418 */ 419 static uint8_t Keyevent2KeycodeFallback(const SDL_KeyboardEvent *ev) 420 { 421 const SDLKey sym = ev->keysym.sym; 422 Log(("SDL key event: sym=%d scancode=%#x unicode=%#x\n", 423 sym, ev->keysym.scancode, ev->keysym.unicode)); 424 switch (sym) 425 { /* set 1 scan code */ 426 case SDLK_ESCAPE: return 0x01; 427 case SDLK_EXCLAIM: 428 case SDLK_1: return 0x02; 429 case SDLK_AT: 430 case SDLK_2: return 0x03; 431 case SDLK_HASH: 432 case SDLK_3: return 0x04; 433 case SDLK_DOLLAR: 434 case SDLK_4: return 0x05; 435 /* % */ 436 case SDLK_5: return 0x06; 437 case SDLK_CARET: 438 case SDLK_6: return 0x07; 439 case SDLK_AMPERSAND: 440 case SDLK_7: return 0x08; 441 case SDLK_ASTERISK: 442 case SDLK_8: return 0x09; 443 case SDLK_LEFTPAREN: 444 case SDLK_9: return 0x0a; 445 case SDLK_RIGHTPAREN: 446 case SDLK_0: return 0x0b; 447 case SDLK_UNDERSCORE: 448 case SDLK_MINUS: return 0x0c; 449 case SDLK_EQUALS: 450 case SDLK_PLUS: return 0x0d; 451 case SDLK_BACKSPACE: return 0x0e; 452 case SDLK_TAB: return 0x0f; 453 case SDLK_q: return 0x10; 454 case SDLK_w: return 0x11; 455 case SDLK_e: return 0x12; 456 case SDLK_r: return 0x13; 457 case SDLK_t: return 0x14; 458 case SDLK_y: return 0x15; 459 case SDLK_u: return 0x16; 460 case SDLK_i: return 0x17; 461 case SDLK_o: return 0x18; 462 case SDLK_p: return 0x19; 463 case SDLK_LEFTBRACKET: return 0x1a; 464 case SDLK_RIGHTBRACKET: return 0x1b; 465 case SDLK_RETURN: return 0x1c; 466 case SDLK_KP_ENTER: return 0x1c | 0x80; 467 case SDLK_LCTRL: return 0x1d; 468 case SDLK_RCTRL: return 0x1d | 0x80; 469 case SDLK_a: return 0x1e; 470 case SDLK_s: return 0x1f; 471 case SDLK_d: return 0x20; 472 case SDLK_f: return 0x21; 473 case SDLK_g: return 0x22; 474 case SDLK_h: return 0x23; 475 case SDLK_j: return 0x24; 476 case SDLK_k: return 0x25; 477 case SDLK_l: return 0x26; 478 case SDLK_COLON: 479 case SDLK_SEMICOLON: return 0x27; 480 case SDLK_QUOTEDBL: 481 case SDLK_QUOTE: return 0x28; 482 case SDLK_BACKQUOTE: return 0x29; 483 case SDLK_LSHIFT: return 0x2a; 484 case SDLK_BACKSLASH: return 0x2b; 485 case SDLK_z: return 0x2c; 486 case SDLK_x: return 0x2d; 487 case SDLK_c: return 0x2e; 488 case SDLK_v: return 0x2f; 489 case SDLK_b: return 0x30; 490 case SDLK_n: return 0x31; 491 case SDLK_m: return 0x32; 492 case SDLK_LESS: 493 case SDLK_COMMA: return 0x33; 494 case SDLK_GREATER: 495 case SDLK_PERIOD: return 0x34; 496 case SDLK_KP_DIVIDE: /*??*/ 497 case SDLK_QUESTION: 498 case SDLK_SLASH: return 0x35; 499 case SDLK_RSHIFT: return 0x36; 500 case SDLK_KP_MULTIPLY: 501 case SDLK_PRINT: return 0x37; /* fixme */ 502 case SDLK_LALT: return 0x38; 503 case SDLK_MODE: /* alt gr*/ 504 case SDLK_RALT: return 0x38 | 0x80; 505 case SDLK_SPACE: return 0x39; 506 case SDLK_CAPSLOCK: return 0x3a; 507 case SDLK_F1: return 0x3b; 508 case SDLK_F2: return 0x3c; 509 case SDLK_F3: return 0x3d; 510 case SDLK_F4: return 0x3e; 511 case SDLK_F5: return 0x3f; 512 case SDLK_F6: return 0x40; 513 case SDLK_F7: return 0x41; 514 case SDLK_F8: return 0x42; 515 case SDLK_F9: return 0x43; 516 case SDLK_F10: return 0x44; 517 case SDLK_PAUSE: return 0x45; /* not right */ 518 case SDLK_NUMLOCK: return 0x45; 519 case SDLK_SCROLLOCK: return 0x46; 520 case SDLK_KP7: return 0x47; 521 case SDLK_HOME: return 0x47 | 0x80; 522 case SDLK_KP8: return 0x48; 523 case SDLK_UP: return 0x48 | 0x80; 524 case SDLK_KP9: return 0x49; 525 case SDLK_PAGEUP: return 0x49 | 0x80; 526 case SDLK_KP_MINUS: return 0x4a; 527 case SDLK_KP4: return 0x4b; 528 case SDLK_LEFT: return 0x4b | 0x80; 529 case SDLK_KP5: return 0x4c; 530 case SDLK_KP6: return 0x4d; 531 case SDLK_RIGHT: return 0x4d | 0x80; 532 case SDLK_KP_PLUS: return 0x4e; 533 case SDLK_KP1: return 0x4f; 534 case SDLK_END: return 0x4f | 0x80; 535 case SDLK_KP2: return 0x50; 536 case SDLK_DOWN: return 0x50 | 0x80; 537 case SDLK_KP3: return 0x51; 538 case SDLK_PAGEDOWN: return 0x51 | 0x80; 539 case SDLK_KP0: return 0x52; 540 case SDLK_INSERT: return 0x52 | 0x80; 541 case SDLK_KP_PERIOD: return 0x53; 542 case SDLK_DELETE: return 0x53 | 0x80; 543 case SDLK_SYSREQ: return 0x54; 544 case SDLK_F11: return 0x57; 545 case SDLK_F12: return 0x58; 546 case SDLK_F13: return 0x5b; 547 case SDLK_LMETA: 548 case SDLK_LSUPER: return 0x5b | 0x80; 549 case SDLK_F14: return 0x5c; 550 case SDLK_RMETA: 551 case SDLK_RSUPER: return 0x5c | 0x80; 552 case SDLK_F15: return 0x5d; 553 case SDLK_MENU: return 0x5d | 0x80; 554 #if 0 555 case SDLK_CLEAR: return 0x; 556 case SDLK_KP_EQUALS: return 0x; 557 case SDLK_COMPOSE: return 0x; 558 case SDLK_HELP: return 0x; 559 case SDLK_BREAK: return 0x; 560 case SDLK_POWER: return 0x; 561 case SDLK_EURO: return 0x; 562 case SDLK_UNDO: return 0x; 563 #endif 564 default: 565 Log(("Unhandled sdl key event: sym=%d scancode=%#x unicode=%#x\n", 566 ev->keysym.sym, ev->keysym.scancode, ev->keysym.unicode)); 567 return 0; 568 } 569 } 570 #endif /* __DARWIN__ */ 409 571 410 572 /** … … 508 670 509 671 #elif defined(__DARWIN__) 510 /* 511 * The keycode on darwin is more or less the same as the SDL key symbol. 512 * This means we'll have to assume a keyboard layout and translate 513 * the SDL / Quartz keycodes via it. 514 * 515 * At first I'll just do a hardcoded us internaltional keyboard mapping 516 * here to try this out. 517 */ 518 /* from SDL: 519 key.scancode = [ event keyCode ]; 520 key.sym = keymap [ key.scancode ]; 521 key.unicode = [ chars characterAtIndex:0 ]; 522 key.mod = KMOD_NONE; */ 523 const SDLKey sym = ev->keysym.sym; 524 if (sym != SDLK_UNKNOWN) 525 { 526 Log(("SDL key event: sym=%d scancode=%#x unicode=%#x\n", 527 sym, ev->keysym.scancode, ev->keysym.unicode)); 528 switch (sym) 529 { /* set 1 scan code */ 530 case SDLK_ESCAPE: return 0x01; 531 case SDLK_EXCLAIM: 532 case SDLK_1: return 0x02; 533 case SDLK_AT: 534 case SDLK_2: return 0x03; 535 case SDLK_HASH: 536 case SDLK_3: return 0x04; 537 case SDLK_DOLLAR: 538 case SDLK_4: return 0x05; 539 /* % */ 540 case SDLK_5: return 0x06; 541 case SDLK_CARET: 542 case SDLK_6: return 0x07; 543 case SDLK_AMPERSAND: 544 case SDLK_7: return 0x08; 545 case SDLK_ASTERISK: 546 case SDLK_8: return 0x09; 547 case SDLK_LEFTPAREN: 548 case SDLK_9: return 0x0a; 549 case SDLK_RIGHTPAREN: 550 case SDLK_0: return 0x0b; 551 case SDLK_UNDERSCORE: 552 case SDLK_MINUS: return 0x0c; 553 case SDLK_EQUALS: 554 case SDLK_PLUS: return 0x0d; 555 case SDLK_BACKSPACE: return 0x0e; 556 case SDLK_TAB: return 0x0f; 557 case SDLK_q: return 0x10; 558 case SDLK_w: return 0x11; 559 case SDLK_e: return 0x12; 560 case SDLK_r: return 0x13; 561 case SDLK_t: return 0x14; 562 case SDLK_y: return 0x15; 563 case SDLK_u: return 0x16; 564 case SDLK_i: return 0x17; 565 case SDLK_o: return 0x18; 566 case SDLK_p: return 0x19; 567 case SDLK_LEFTBRACKET: return 0x1a; 568 case SDLK_RIGHTBRACKET: return 0x1b; 569 case SDLK_RETURN: return 0x1c; 570 case SDLK_KP_ENTER: return 0x1c | 0x80; 571 case SDLK_LCTRL: return 0x1d; 572 case SDLK_RCTRL: return 0x1d | 0x80; 573 case SDLK_a: return 0x1e; 574 case SDLK_s: return 0x1f; 575 case SDLK_d: return 0x20; 576 case SDLK_f: return 0x21; 577 case SDLK_g: return 0x22; 578 case SDLK_h: return 0x23; 579 case SDLK_j: return 0x24; 580 case SDLK_k: return 0x25; 581 case SDLK_l: return 0x26; 582 case SDLK_COLON: 583 case SDLK_SEMICOLON: return 0x27; 584 case SDLK_QUOTEDBL: 585 case SDLK_QUOTE: return 0x28; 586 case SDLK_BACKQUOTE: return 0x29; 587 case SDLK_LSHIFT: return 0x2a; 588 case SDLK_BACKSLASH: return 0x2b; 589 case SDLK_z: return 0x2c; 590 case SDLK_x: return 0x2d; 591 case SDLK_c: return 0x2e; 592 case SDLK_v: return 0x2f; 593 case SDLK_b: return 0x30; 594 case SDLK_n: return 0x31; 595 case SDLK_m: return 0x32; 596 case SDLK_LESS: 597 case SDLK_COMMA: return 0x33; 598 case SDLK_GREATER: 599 case SDLK_PERIOD: return 0x34; 600 case SDLK_KP_DIVIDE: /*??*/ 601 case SDLK_QUESTION: 602 case SDLK_SLASH: return 0x35; 603 case SDLK_RSHIFT: return 0x36; 604 case SDLK_KP_MULTIPLY: 605 case SDLK_PRINT: return 0x37; /* fixme */ 606 case SDLK_LALT: return 0x38; 607 case SDLK_MODE: /* alt gr*/ 608 case SDLK_RALT: return 0x38 | 0x80; 609 case SDLK_SPACE: return 0x39; 610 case SDLK_CAPSLOCK: return 0x3a; 611 case SDLK_F1: return 0x3b; 612 case SDLK_F2: return 0x3c; 613 case SDLK_F3: return 0x3d; 614 case SDLK_F4: return 0x3e; 615 case SDLK_F5: return 0x3f; 616 case SDLK_F6: return 0x40; 617 case SDLK_F7: return 0x41; 618 case SDLK_F8: return 0x42; 619 case SDLK_F9: return 0x43; 620 case SDLK_F10: return 0x44; 621 case SDLK_PAUSE: return 0x45; /* fixme */ 622 case SDLK_NUMLOCK: return 0x45; 623 case SDLK_SCROLLOCK: return 0x46; 624 case SDLK_KP7: return 0x47; 625 case SDLK_HOME: return 0x47 | 0x80; 626 case SDLK_KP8: return 0x48; 627 case SDLK_UP: return 0x48 | 0x80; 628 case SDLK_KP9: return 0x49; 629 case SDLK_PAGEUP: return 0x49 | 0x80; 630 case SDLK_KP_MINUS: return 0x4a; 631 case SDLK_KP4: return 0x4b; 632 case SDLK_LEFT: return 0x4b | 0x80; 633 case SDLK_KP5: return 0x4c; 634 case SDLK_KP6: return 0x4d; 635 case SDLK_RIGHT: return 0x4d | 0x80; 636 case SDLK_KP_PLUS: return 0x4e; 637 case SDLK_KP1: return 0x4f; 638 case SDLK_END: return 0x4f | 0x80; 639 case SDLK_KP2: return 0x50; 640 case SDLK_DOWN: return 0x50 | 0x80; 641 case SDLK_KP3: return 0x51; 642 case SDLK_PAGEDOWN: return 0x51 | 0x80; 643 case SDLK_KP0: return 0x52; 644 case SDLK_INSERT: return 0x52 | 0x80; 645 case SDLK_KP_PERIOD: return 0x53; 646 case SDLK_DELETE: return 0x53 | 0x80; 647 case SDLK_SYSREQ: return 0x54; 648 case SDLK_F11: return 0x56; 649 case SDLK_F12: return 0x57; 650 case SDLK_F13: return 0x5b; 651 case SDLK_LSUPER: return 0x5b | 0x80; 652 case SDLK_F14: return 0x5c; 653 case SDLK_RSUPER: return 0x5c | 0x80; 654 case SDLK_F15: return 0x5d; 655 case SDLK_MENU: return 0x5d | 0x80; 656 #if 0 /* @todo */ 657 case SDLK_CLEAR: return 0x; 658 case SDLK_KP_EQUALS: return 0x; 659 case SDLK_RMETA: return 0x; 660 case SDLK_LMETA: return 0x; 661 case SDLK_COMPOSE: return 0x; 662 case SDLK_HELP: return 0x; 663 case SDLK_BREAK: return 0x; 664 case SDLK_POWER: return 0x; 665 case SDLK_EURO: return 0x; 666 case SDLK_UNDO: return 0x; 667 #endif 668 default: 669 Log(("Unhandled sdl key event: sym=%d scancode=%#x unicode=%#x\n", 670 ev->keysym.sym, ev->keysym.scancode, ev->keysym.unicode)); 671 keycode = 0; 672 break; 673 } 674 } 675 else 676 { 677 /* deal with this as needed. mac can emit pure unicode events */ 678 Log(("Unhandled key event: scancode=%#x unicode=%#x\n", 679 ev->keysym.scancode, ev->keysym.unicode)); 680 } 672 /* This is derived partially from SDL_QuartzKeys.h and partially from testing. */ 673 static const uint8_t s_aMacToSet1[] = 674 { 675 /* set-1 SDL_QuartzKeys.h */ 676 0x1e, /* QZ_a 0x00 */ 677 0x1f, /* QZ_s 0x01 */ 678 0x20, /* QZ_d 0x02 */ 679 0x21, /* QZ_f 0x03 */ 680 0x23, /* QZ_h 0x04 */ 681 0x22, /* QZ_g 0x05 */ 682 0x2c, /* QZ_z 0x06 */ 683 0x2d, /* QZ_x 0x07 */ 684 0x2e, /* QZ_c 0x08 */ 685 0x2f, /* QZ_v 0x09 */ 686 0x56, /* between lshift and z. 'INT 1'? */ 687 0x30, /* QZ_b 0x0B */ 688 0x10, /* QZ_q 0x0C */ 689 0x11, /* QZ_w 0x0D */ 690 0x12, /* QZ_e 0x0E */ 691 0x13, /* QZ_r 0x0F */ 692 0x15, /* QZ_y 0x10 */ 693 0x14, /* QZ_t 0x11 */ 694 0x02, /* QZ_1 0x12 */ 695 0x03, /* QZ_2 0x13 */ 696 0x04, /* QZ_3 0x14 */ 697 0x05, /* QZ_4 0x15 */ 698 0x07, /* QZ_6 0x16 */ 699 0x06, /* QZ_5 0x17 */ 700 0x0d, /* QZ_EQUALS 0x18 */ 701 0x0a, /* QZ_9 0x19 */ 702 0x08, /* QZ_7 0x1A */ 703 0x0c, /* QZ_MINUS 0x1B */ 704 0x09, /* QZ_8 0x1C */ 705 0x0b, /* QZ_0 0x1D */ 706 0x1b, /* QZ_RIGHTBRACKET 0x1E */ 707 0x18, /* QZ_o 0x1F */ 708 0x16, /* QZ_u 0x20 */ 709 0x1a, /* QZ_LEFTBRACKET 0x21 */ 710 0x17, /* QZ_i 0x22 */ 711 0x19, /* QZ_p 0x23 */ 712 0x1c, /* QZ_RETURN 0x24 */ 713 0x26, /* QZ_l 0x25 */ 714 0x24, /* QZ_j 0x26 */ 715 0x28, /* QZ_QUOTE 0x27 */ 716 0x25, /* QZ_k 0x28 */ 717 0x27, /* QZ_SEMICOLON 0x29 */ 718 0x2b, /* QZ_BACKSLASH 0x2A */ 719 0x33, /* QZ_COMMA 0x2B */ 720 0x35, /* QZ_SLASH 0x2C */ 721 0x31, /* QZ_n 0x2D */ 722 0x32, /* QZ_m 0x2E */ 723 0x34, /* QZ_PERIOD 0x2F */ 724 0x0f, /* QZ_TAB 0x30 */ 725 0x39, /* QZ_SPACE 0x31 */ 726 0x29, /* QZ_BACKQUOTE 0x32 */ 727 0x0e, /* QZ_BACKSPACE 0x33 */ 728 0x9c, /* QZ_IBOOK_ENTER 0x34 */ 729 0x01, /* QZ_ESCAPE 0x35 */ 730 0x5c|0x80, /* QZ_RMETA 0x36 */ 731 0x5b|0x80, /* QZ_LMETA 0x37 */ 732 0x2a, /* QZ_LSHIFT 0x38 */ 733 0x3a, /* QZ_CAPSLOCK 0x39 */ 734 0x38, /* QZ_LALT 0x3A */ 735 0x1d, /* QZ_LCTRL 0x3B */ 736 0x36, /* QZ_RSHIFT 0x3C */ 737 0x38|0x80, /* QZ_RALT 0x3D */ 738 0x1d|0x80, /* QZ_RCTRL 0x3E */ 739 0, /* */ 740 0, /* */ 741 0x53, /* QZ_KP_PERIOD 0x41 */ 742 0, /* */ 743 0x37, /* QZ_KP_MULTIPLY 0x43 */ 744 0, /* */ 745 0x4e, /* QZ_KP_PLUS 0x45 */ 746 0, /* */ 747 0x45, /* QZ_NUMLOCK 0x47 */ 748 0, /* */ 749 0, /* */ 750 0, /* */ 751 0x35|0x80, /* QZ_KP_DIVIDE 0x4B */ 752 0x1c|0x80, /* QZ_KP_ENTER 0x4C */ 753 0, /* */ 754 0x4a, /* QZ_KP_MINUS 0x4E */ 755 0, /* */ 756 0, /* */ 757 0x0d/*?*/, /* QZ_KP_EQUALS 0x51 */ 758 0x52, /* QZ_KP0 0x52 */ 759 0x4f, /* QZ_KP1 0x53 */ 760 0x50, /* QZ_KP2 0x54 */ 761 0x51, /* QZ_KP3 0x55 */ 762 0x4b, /* QZ_KP4 0x56 */ 763 0x4c, /* QZ_KP5 0x57 */ 764 0x4d, /* QZ_KP6 0x58 */ 765 0x47, /* QZ_KP7 0x59 */ 766 0, /* */ 767 0x48, /* QZ_KP8 0x5B */ 768 0x49, /* QZ_KP9 0x5C */ 769 0, /* */ 770 0, /* */ 771 0, /* */ 772 0x3f, /* QZ_F5 0x60 */ 773 0x40, /* QZ_F6 0x61 */ 774 0x41, /* QZ_F7 0x62 */ 775 0x3d, /* QZ_F3 0x63 */ 776 0x42, /* QZ_F8 0x64 */ 777 0x43, /* QZ_F9 0x65 */ 778 0, /* */ 779 0x57, /* QZ_F11 0x67 */ 780 0, /* */ 781 0x37|0x80, /* QZ_PRINT / F13 0x69 */ 782 0x63, /* QZ_F16 0x6A */ 783 0x46, /* QZ_SCROLLOCK 0x6B */ 784 0, /* */ 785 0x44, /* QZ_F10 0x6D */ 786 0x5d|0x80, /* */ 787 0x58, /* QZ_F12 0x6F */ 788 0, /* */ 789 0/* 0xe1,0x1d,0x45*/, /* QZ_PAUSE 0x71 */ 790 0x52|0x80, /* QZ_INSERT / HELP 0x72 */ 791 0x47|0x80, /* QZ_HOME 0x73 */ 792 0x49|0x80, /* QZ_PAGEUP 0x74 */ 793 0x53|0x80, /* QZ_DELETE 0x75 */ 794 0x3e, /* QZ_F4 0x76 */ 795 0x4f|0x80, /* QZ_END 0x77 */ 796 0x3c, /* QZ_F2 0x78 */ 797 0x51|0x80, /* QZ_PAGEDOWN 0x79 */ 798 0x3b, /* QZ_F1 0x7A */ 799 0x4b|0x80, /* QZ_LEFT 0x7B */ 800 0x4d|0x80, /* QZ_RIGHT 0x7C */ 801 0x50|0x80, /* QZ_DOWN 0x7D */ 802 0x48|0x80, /* QZ_UP 0x7E */ 803 0x5e|0x80, /* QZ_POWER 0x7F */ /* have different break key! */ 804 }; 805 806 if (keycode == 0) 807 { 808 /* This could be a modifier or it could be 'a'. */ 809 switch (ev->keysym.sym) 810 { 811 case SDLK_LSHIFT: keycode = 0x2a; break; 812 case SDLK_RSHIFT: keycode = 0x36; break; 813 case SDLK_LCTRL: keycode = 0x1d; break; 814 case SDLK_RCTRL: keycode = 0x1d | 0x80; break; 815 case SDLK_LALT: keycode = 0x38; break; 816 case SDLK_MODE: /* alt gr */ 817 case SDLK_RALT: keycode = 0x38 | 0x80; break; 818 case SDLK_RMETA: 819 case SDLK_RSUPER: keycode = 0x5c | 0x80; break; 820 case SDLK_LMETA: 821 case SDLK_LSUPER: keycode = 0x5b | 0x80; break; 822 /* Sssumes normal key. */ 823 default: keycode = s_aMacToSet1[keycode]; break; 824 } 825 } 826 else 827 { 828 if ((unsigned)keycode < RT_ELEMENTS(s_aMacToSet1)) 829 keycode = s_aMacToSet1[keycode]; 830 else 831 keycode = 0; 832 if (!keycode) 833 { 834 #ifdef DEBUG_bird 835 RTPrintf("Untranslated: keycode=%#x (%d)\n", keycode, keycode); 836 #endif 837 keycode = Keyevent2KeycodeFallback(ev); 838 } 839 } 840 #ifdef DEBUG_bird 841 RTPrintf("scancode=%#x -> %#x\n", ev->keysym.scancode, keycode); 842 #endif 843 681 844 #endif 682 845 return keycode;
Note:
See TracChangeset
for help on using the changeset viewer.