46 #include <private/qevent_p.h> 47 #include <private/qlocale_p.h> 48 #include <private/qapplication_p.h> 63 #define LANG_PASHTO 0x63 66 #define LANG_SYRIAC 0x5a 69 #define LANG_DIVEHI 0x65 72 #define VK_OEM_PLUS 0xBB 77 #ifndef MAPVK_VK_TO_CHAR 78 #define MAPVK_VK_TO_CHAR (2) 81 #if defined(Q_OS_WINCE) 84 for (
int i=0; i< 256; ++i)
85 kbuffer[i] = GetAsyncKeyState(i);
113 inline void clearKeys();
124 for (
int i = 0; i < nrecs; ++i) {
125 if (records[i].code == code) {
127 deleted_record = records[i];
129 while (i + 1 < nrecs) {
130 records[i] = records[i + 1];
134 result = &deleted_record;
136 result = &records[i];
147 "Internal KeyRecorder",
148 "Keyboard recorder buffer overflow, consider increasing QT_MAX_KEY_RECORDINGS");
151 qWarning(
"Qt: Internal keyboard buffer overflow");
154 records[nrecs++] =
KeyRecord(code,ascii,state,text);
433 static const Qt::KeyboardModifiers
ModsTbl[] = {
450 #if defined(Q_OS_WINCE_WM) && defined(QT_KEYPAD_NAVIGATION) 453 if (keyCode == VK_RETURN && QApplication::keypadNavigationEnabled())
462 #if defined(Q_OS_WINCE) 468 int ToUnicode(UINT vk,
int ,
unsigned char* , LPWSTR unicodeBuffer,
int,
int)
471 QChar* buf =
reinterpret_cast< QChar*
>(unicodeBuffer);
479 int ToAscii(UINT vk,
int scancode,
unsigned char *kbdBuffer, LPWORD unicodeBuffer,
int flag)
481 return ToUnicode(vk, scancode, kbdBuffer, (LPWSTR) unicodeBuffer, 0, flag);
489 static inline int toKeyOrUnicode(
int vk,
int scancode,
unsigned char *kbdBuffer,
bool *isDeadkey = 0)
493 QChar unicodeBuffer[5];
494 int res =
ToUnicode(vk, scancode, kbdBuffer, reinterpret_cast<LPWSTR>(unicodeBuffer), 5, 0);
497 if (res == 0 && kbdBuffer[VK_CONTROL]) {
498 const unsigned char controlState = kbdBuffer[VK_CONTROL];
499 kbdBuffer[VK_CONTROL] = 0;
500 res =
ToUnicode(vk, scancode, kbdBuffer, reinterpret_cast<LPWSTR>(unicodeBuffer), 5, 0);
501 kbdBuffer[VK_CONTROL] = controlState;
508 if (code < 0x20 || code == 0x7f)
512 *isDeadkey = (res == -1);
525 if (a >=
'a' && a <=
'z')
528 if (a >= 0 && a <= 31)
548 #define enabled (MF_BYCOMMAND | MF_ENABLED) 549 #define disabled (MF_BYCOMMAND | MF_GRAYED) 556 EnableMenuItem(menu, SC_RESTORE, maximized?enabled:disabled);
562 EnableMenuItem(menu, SC_MOVE, maximized?disabled:enabled);
563 EnableMenuItem(menu, SC_CLOSE, enabled);
565 MENUITEMINFO closeItem;
566 closeItem.cbSize =
sizeof(MENUITEMINFO);
567 closeItem.fMask = MIIM_STATE;
568 closeItem.fState = MFS_DEFAULT;
569 SetMenuItemInfo(menu, SC_CLOSE,
FALSE, &closeItem);
574 int ret = TrackPopupMenuEx(menu,
575 TPM_LEFTALIGN | TPM_TOPALIGN | TPM_NONOTIFY | TPM_RETURNCMD,
614 memset(keyLayout, 0,
sizeof(keyLayout));
624 for (
int i = 0; i < 255; ++i) {
639 LCID newLCID = MAKELCID((
quintptr)GetKeyboardLayout(0), SORT_DEFAULT);
643 wchar_t LCIDFontSig[16];
644 if (GetLocaleInfo(newLCID, LOCALE_FONTSIGNATURE, LCIDFontSig,
sizeof(LCIDFontSig) /
sizeof(
wchar_t))
645 && (LCIDFontSig[7] & (
wchar_t)0x0800))
659 kbd[VK_LSHIFT ] = (shift ? 0x80 : 0);
660 kbd[VK_SHIFT ] = (shift ? 0x80 : 0);
661 kbd[VK_LCONTROL] = (ctrl ? 0x80 : 0);
662 kbd[VK_CONTROL ] = (ctrl ? 0x80 : 0);
663 kbd[VK_RMENU ] = (alt ? 0x80 : 0);
664 kbd[VK_MENU ] = (alt ? 0x80 : 0);
669 unsigned char kbdBuffer[256];
672 updatePossibleKeyCodes(kbdBuffer, scancode, msg.wParam);
678 if (!vk_key || (keyLayout[vk_key] && !keyLayout[vk_key]->dirty))
681 if (!keyLayout[vk_key])
685 unsigned char buffer[256];
686 memcpy(buffer, kbdBuffer,
sizeof(buffer));
688 buffer[VK_LWIN ] = 0;
689 buffer[VK_RWIN ] = 0;
690 buffer[VK_CAPITAL ] = 0;
691 buffer[VK_NUMLOCK ] = 0;
692 buffer[VK_SCROLL ] = 0;
694 buffer[VK_RSHIFT ] = 0;
695 buffer[VK_RCONTROL] = 0;
696 buffer[VK_LMENU ] = 0;
698 bool isDeadKey =
false;
699 keyLayout[vk_key]->deadkeys = 0;
700 keyLayout[vk_key]->dirty =
false;
702 keyLayout[vk_key]->qtKey[0] =
toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
703 keyLayout[vk_key]->deadkeys |= isDeadKey ? 0x01 : 0;
705 keyLayout[vk_key]->qtKey[1] =
toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
706 keyLayout[vk_key]->deadkeys |= isDeadKey ? 0x02 : 0;
708 keyLayout[vk_key]->qtKey[2] =
toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
709 keyLayout[vk_key]->deadkeys |= isDeadKey ? 0x04 : 0;
711 keyLayout[vk_key]->qtKey[3] =
toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
712 keyLayout[vk_key]->deadkeys |= isDeadKey ? 0x08 : 0;
714 keyLayout[vk_key]->qtKey[4] =
toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
715 keyLayout[vk_key]->deadkeys |= isDeadKey ? 0x10 : 0;
717 keyLayout[vk_key]->qtKey[5] =
toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
718 keyLayout[vk_key]->deadkeys |= isDeadKey ? 0x20 : 0;
720 keyLayout[vk_key]->qtKey[6] =
toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
721 keyLayout[vk_key]->deadkeys |= isDeadKey ? 0x40 : 0;
723 keyLayout[vk_key]->qtKey[7] =
toKeyOrUnicode(vk_key, scancode, buffer, &isDeadKey);
724 keyLayout[vk_key]->deadkeys |= isDeadKey ? 0x80 : 0;
729 if (vk_key != keyLayout[vk_key]->
qtKey[0] && vk_key < 0x5B && vk_key > 0x2F)
730 fallbackKey = vk_key;
732 keyLayout[vk_key]->qtKey[8] = fallbackKey;
735 if (keyLayout[vk_key]->deadkeys) {
742 unsigned char emptyBuffer[256];
743 memset(emptyBuffer, 0,
sizeof(emptyBuffer));
744 ::ToAscii(VK_SPACE, 0, emptyBuffer, reinterpret_cast<LPWORD>(&buffer), 0);
745 ::ToAscii(vk_key, scancode, kbdBuffer, reinterpret_cast<LPWORD>(&buffer), 0);
748 #ifdef DEBUG_KEYMAPPER 749 qDebug(
"updatePossibleKeyCodes for virtual key = 0x%02x!", vk_key);
750 for (
int i = 0; i < 9; ++i) {
751 qDebug(
" [%d] (%d,0x%02x,'%c') %s", i,
752 keyLayout[vk_key]->
qtKey[i],
753 keyLayout[vk_key]->
qtKey[i],
754 keyLayout[vk_key]->
qtKey[i] ? keyLayout[vk_key]->
qtKey[i] : 0x03,
755 keyLayout[vk_key]->deadkeys & (1<<i) ?
"deadkey" :
"");
757 #endif // DEBUG_KEYMAPPER 762 if (keyLayout && (vk_key < 256) && keyLayout[vk_key]) {
763 for(
register int i = 0; i < 9; ++i) {
765 return bool(keyLayout[vk_key]->deadkeys & 1<<i);
777 if (nativeVirtualKey > 255)
785 Qt::KeyboardModifiers keyMods = e->
modifiers();
790 result << int(baseKey + keyMods);
792 for(
int i = 1; i < 9; ++i) {
793 Qt::KeyboardModifiers neededMods =
ModsTbl[i];
795 if (key && key != baseKey && ((keyMods & neededMods) == neededMods))
796 result << int(key + (keyMods & ~neededMods));
808 int msgType = msg.message;
812 if (msg.message != WM_CHAR && msg.message != WM_IME_CHAR)
816 const quint32 vk_key = msg.wParam;
820 #if defined(Q_OS_WINCE) 821 nModifiers |= (GetKeyState(VK_SHIFT ) < 0 ?
ShiftAny : 0);
822 nModifiers |= (GetKeyState(VK_CONTROL) < 0 ?
ControlAny : 0);
823 nModifiers |= (GetKeyState(VK_MENU ) < 0 ?
AltAny : 0);
824 nModifiers |= (GetKeyState(VK_LWIN ) < 0 ?
MetaLeft : 0);
825 nModifiers |= (GetKeyState(VK_RWIN ) < 0 ?
MetaRight : 0);
828 nModifiers |= (GetKeyState(VK_LSHIFT ) & 0x80 ?
ShiftLeft : 0);
829 nModifiers |= (GetKeyState(VK_RSHIFT ) & 0x80 ?
ShiftRight : 0);
830 nModifiers |= (GetKeyState(VK_LCONTROL) & 0x80 ?
ControlLeft : 0);
831 nModifiers |= (GetKeyState(VK_RCONTROL) & 0x80 ?
ControlRight : 0);
832 nModifiers |= (GetKeyState(VK_LMENU ) & 0x80 ?
AltLeft : 0);
833 nModifiers |= (GetKeyState(VK_RMENU ) & 0x80 ?
AltRight : 0);
834 nModifiers |= (GetKeyState(VK_LWIN ) & 0x80 ?
MetaLeft : 0);
835 nModifiers |= (GetKeyState(VK_RWIN ) & 0x80 ?
MetaRight : 0);
837 nModifiers |= (GetKeyState(VK_CAPITAL ) & 0x01 ?
CapsLock : 0);
838 nModifiers |= (GetKeyState(VK_NUMLOCK ) & 0x01 ?
NumLock : 0);
839 nModifiers |= (GetKeyState(VK_SCROLL ) & 0x01 ?
ScrollLock : 0);
853 if (msgType == WM_CHAR) {
859 k0 = q->sendKeyEvent(widget, grab,
QEvent::KeyPress, 0,
Qt::KeyboardModifier(state), s,
false, 0, scancode, vk_key, nModifiers);
860 k1 = q->sendKeyEvent(widget, grab,
QEvent::KeyRelease, 0,
Qt::KeyboardModifier(state), s,
false, 0, scancode, vk_key, nModifiers);
864 else if (msgType == WM_IME_CHAR) {
870 k0 = q->sendKeyEvent(widget, grab,
QEvent::KeyPress, 0,
Qt::KeyboardModifier(state), s,
false, 0, scancode, vk_key, nModifiers);
871 k1 = q->sendKeyEvent(widget, grab,
QEvent::KeyRelease, 0,
Qt::KeyboardModifier(state), s,
false, 0, scancode, vk_key, nModifiers);
877 static int dirStatus = 0;
879 && msg.wParam == VK_CONTROL
880 && msgType == WM_KEYDOWN) {
881 if (GetKeyState(VK_LCONTROL) < 0)
882 dirStatus = VK_LCONTROL;
883 else if (GetKeyState(VK_RCONTROL) < 0)
884 dirStatus = VK_RCONTROL;
885 }
else if (dirStatus) {
886 if (msgType == WM_KEYDOWN) {
887 if (msg.wParam == VK_SHIFT) {
888 if (dirStatus == VK_LCONTROL && GetKeyState(VK_LSHIFT) < 0)
889 dirStatus = VK_LSHIFT;
890 else if (dirStatus == VK_RCONTROL && GetKeyState(VK_RSHIFT) < 0)
891 dirStatus = VK_RSHIFT;
895 }
else if (msgType == WM_KEYUP) {
896 if (dirStatus == VK_LSHIFT
897 && ((msg.wParam == VK_SHIFT && GetKeyState(VK_LCONTROL))
898 || (msg.wParam == VK_CONTROL && GetKeyState(VK_LSHIFT)))) {
901 scancode, msg.wParam, nModifiers);
904 scancode, msg.wParam, nModifiers);
906 }
else if (dirStatus == VK_RSHIFT
907 && ( (msg.wParam == VK_SHIFT && GetKeyState(VK_RCONTROL))
908 || (msg.wParam == VK_CONTROL && GetKeyState(VK_RSHIFT)))) {
911 scancode, msg.wParam, nModifiers);
914 scancode, msg.wParam, nModifiers);
926 if(msg.wParam == VK_PROCESSKEY)
930 if (msg.wParam == 0 || msg.wParam == 0xFF)
934 int modifiersIndex = 0;
935 modifiersIndex |= (nModifiers &
ShiftAny ? 0x1 : 0);
936 modifiersIndex |= (nModifiers &
ControlAny ? 0x2 : 0);
937 modifiersIndex |= (nModifiers &
AltAny ? 0x4 : 0);
939 int code = keyLayout[vk_key]->qtKey[modifiersIndex];
957 if (!(msg.lParam & 0x1000000)) {
983 state |= ((msg.wParam >=
'0' && msg.wParam <=
'9')
987 if ((
uint)msg.lParam == 0x004c0001 || (
uint)msg.lParam == 0xc04c0001)
1005 if (msgType == WM_KEYDOWN || msgType == WM_IME_KEYDOWN || msgType == WM_SYSKEYDOWN) {
1013 if (rec && rec->
state != state) {
1014 key_recorder.
findKey(msg.wParam,
true);
1020 UINT charType = (msgType == WM_KEYDOWN
1022 : msgType == WM_IME_KEYDOWN ? WM_IME_CHAR : WM_SYSCHAR);
1025 if (PeekMessage(&wm_char, 0, charType, charType, PM_REMOVE)) {
1030 if (!code && !uch.
row())
1038 if (uch.
isNull() && msgType == WM_IME_KEYDOWN) {
1040 wchar_t newKey[3] = {0};
1042 int val =
ToUnicode(vk_key, scancode, keyState, newKey, 2, 0);
1044 uch =
QChar(newKey[0]);
1054 if (msg.wParam == VK_DELETE) {
1057 if (msgType != WM_SYSKEYDOWN || !code) {
1058 UINT
map = MapVirtualKey(msg.wParam, 2);
1060 if (!(map & 0x80000000))
1064 if (!code && !uch.
row())
1069 if (state == Qt::AltModifier) {
1095 scancode, msg.wParam, nModifiers);
1098 scancode, msg.wParam, nModifiers);
1107 char a = uch.
row() ? 0 : uch.
cell();
1108 key_recorder.
storeKey(msg.wParam, a, state, text);
1110 text,
false, 0, scancode, msg.wParam, nModifiers);
1114 #if !defined(Q_OS_WINCE) 1115 if (msgType == WM_SYSKEYDOWN && !k0 && a) {
1118 if (GetMenu(parent)) {
1119 SendMessage(parent, WM_SYSCOMMAND, SC_KEYMENU, a);
1124 parent = GetParent(parent);
1129 key_recorder.
findKey(msg.wParam,
true);
1150 if (code ==
Qt::Key_Tab && (state & Qt::ShiftModifier) == Qt::ShiftModifier)
1154 (rec ? rec->
text :
QString()),
false, 0, scancode, msg.wParam, nModifiers);
1157 #if !defined(Q_OS_WINCE) 1166 parent = GetParent(parent);
1187 #if defined(Q_OS_WINCE) 1191 #if defined QT3_SUPPORT && !defined(QT_NO_SHORTCUT) 1197 text, autorepeat,
qMax(1,
int(text.
length())),
1198 nativeScanCode, nativeVirtualKey, nativeModifiers);
1209 text, autorepeat,
qMax(1,
int(text.
length())),
1210 nativeScanCode, nativeVirtualKey, nativeModifiers);
static const int QT_MAX_KEY_RECORDINGS
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
The QKeyEvent class describes a key event.
static void beep()
Sounds the bell, using the default volume and sound.
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
QIntegerForSizeof< void * >::Unsigned quintptr
#define QT_END_NAMESPACE
This macro expands to.
QPointer< QWidget > widget
void updatePossibleKeyCodes(unsigned char *kbdBuffer, quint32 scancode, quint32 vk_key)
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isNull() const
Returns true if the character is the Unicode character 0x0000 ('\0'); otherwise returns false...
bool qt_use_rtl_extensions
KeyRecord * findKey(int code, bool remove)
KeyRecord(int c, int a, int s, const QString &t)
int length() const
Returns the number of characters in this string.
quint32 nativeModifiers() const
Returns the native modifiers of a key event.
Q_GUI_EXPORT int qt_translateKeyCode(int vk)
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
LRESULT QT_WIN_CALLBACK QtWndProc(HWND, UINT, WPARAM, LPARAM)
static QApplicationPrivate * instance()
long ASN1_INTEGER_get ASN1_INTEGER * a
The QString class provides a Unicode character string.
bool isADeadKey(unsigned int vk_key, unsigned int modifiers)
void updateKeyMap(const MSG &msg)
void setKbdState(unsigned char *kbd, bool shift, bool ctrl, bool alt)
int ToUnicode(UINT vk, int, unsigned char *, LPWSTR unicodeBuffer, int, int)
The QObject class is the base class of all Qt objects.
The QChar class provides a 16-bit Unicode character.
static void qt_show_system_menu(QWidget *tlw)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Q_CORE_EXPORT void qDebug(const char *,...)
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
QList< int > possibleKeys(QKeyEvent *e)
#define QT_BEGIN_NAMESPACE
This macro expands to.
static const uint KeyTbl[]
int winceKeyBend(int keyCode)
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event)
Q_CORE_EXPORT void qWarning(const char *,...)
#define FALSE
Synonym for false.
bool translateKeyEvent(QWidget *receiver, const MSG &msg, bool grab)
QChar toUpper() const
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
static int asciiToKeycode(char a, int state)
void storeKey(int code, int ascii, int state, const QString &text)
#define Q_ASSERT_X(cond, where, what)
Type
This enum type defines the valid event types in Qt.
int ToAscii(UINT vk, int scancode, unsigned char *kbdBuffer, LPWORD unicodeBuffer, int flag)
static bool isModifierKey(int code)
int y() const
Returns the y-coordinate of the rectangle's top edge.
int x() const
Returns the x-coordinate of the rectangle's left edge.
uchar cell() const
Returns the cell (least significant byte) of the Unicode character.
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
static bool sendKeyEvent(QWidget *widget, bool grab, QEvent::Type type, int code, Qt::KeyboardModifiers modifiers, const QString &text, bool autorepeat, int count, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, bool *unusedExceptForCocoa=0)
static const Qt::KeyboardModifiers ModsTbl[]
static int toKeyOrUnicode(int vk, int scancode, unsigned char *kbdBuffer, bool *isDeadkey=0)
static KeyRecorder key_recorder
static QString qtKey(CFStringRef cfkey)
The QEvent class is the base class of all event classes.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
QChar toLower() const
Returns the lowercase equivalent if the character is uppercase or titlecase; otherwise returns the ch...
uchar row() const
Returns the row (most significant byte) of the Unicode character.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
quint32 nativeVirtualKey() const
Returns the native virtual key, or key sym of the key event.
bool GetKeyboardState(unsigned char *kbuffer)
Q_CORE_EXPORT QLocale qt_localeFromLCID(LCID id)