{
this->parent = parent;
this->mtTracker = NULL;
- this->numLockState = false;
- this->capsLockState = false;
+
+ this->hostNumLockState = false;
+ this->guestNumLockState = false;
+ this->hostCapsLockState = false;
+ this->guestCapsLockState = false;
createKeyMap();
createKeypadMap();
int KeyboardHelper::keyCodeOperation(QKeyEvent *event, int keyCode)
{
/* keypad and specialKey translation */
- if (!numLockState && (event->modifiers() == (Qt::KeypadModifier | Qt::ShiftModifier))) {
+ if (!hostNumLockState && (event->modifiers() == (Qt::KeypadModifier | Qt::ShiftModifier))) {
QMap<int, int>::iterator keypadIter = keypadMap.find(keyCode);
while (keypadIter != keypadMap.end()) {
if (keypadIter.key() == keyCode) {
void KeyboardHelper::changeCapsLockState(void)
{
- if (get_emul_caps_lock_state() != capsLockState) {
+ if (guestCapsLockState != hostCapsLockState) {
virtio_keyboard_event(58);
virtio_keyboard_event(58 | 0x80);
- set_emul_caps_lock_state(get_emul_caps_lock_state() ^ 1);
+ guestCapsLockState = !guestCapsLockState; /* toggle */
- qDebug() << "qemu CapsLock state was synchronized with host key value (" <<
- get_emul_caps_lock_state() << ")";
+ qDebug() << "CapsLock state was synchronized:" << guestCapsLockState;
}
}
/* NumLock or CapsLock key */
if (keyCode == Qt::Key_NumLock) {
+ qDebug("num_lock pressed");
+
#ifdef CONFIG_WIN32
if (event->nativeModifiers() == 0x1000200) {
- numLockState = ON;
+ hostNumLockState = true;
} else if (event->nativeModifiers() == 0x1000000) {
- numLockState = OFF;
+ hostNumLockState = false;
}
#else
if (event->nativeModifiers() == 0) {
- numLockState = ON;
+ hostNumLockState = true;
} else if (event->nativeModifiers() == 16) {
- numLockState = OFF;
+ hostNumLockState = false;
}
#endif
- qDebug() << "num_lock state:" << numLockState << "pressed";
+
return;
} else if (keyCode == Qt::Key_CapsLock) {
+ qDebug("caps_lock pressed");
+
#ifdef CONFIG_WIN32
if (event->nativeModifiers() == 256) {
- capsLockState = ON;
+ hostCapsLockState = true;
} else if (event->nativeModifiers() == 0) {
- capsLockState = OFF;
+ hostCapsLockState = false;
}
#elif defined(CONFIG_DARWIN)
- capsLockState = ON;
+ hostCapsLockState = true;
changeCapsLockState();
#else
if (event->nativeModifiers() == 18) {
- capsLockState = ON;
+ hostCapsLockState = true;
} else if (event->nativeModifiers() == 16) {
- capsLockState = OFF;
+ hostCapsLockState = false;
}
#endif
- qDebug() << "caps_lock state(" << capsLockState << ") pressed";
+
return;
}
if ((event->modifiers() & Qt::KeypadModifier)) {
if (isSpecialKey(keyCode) || keyCode == Qt::Key_Clear) {
if (!(event->modifiers() & Qt::ShiftModifier)) {
- numLockState = OFF;
+ hostNumLockState = false;
} else {
- numLockState = ON;
+ hostNumLockState = true;
}
} else {
if (!((event->modifiers() & Qt::ShiftModifier) ||
keyCode == 42 || keyCode == 43 || keyCode == 45 || keyCode == 47))
{ /* (42 = *, 43 = +, 45 = -, 47 = /) on keypad */
- numLockState = ON;
+ hostNumLockState = true;
} else {
- numLockState = OFF;
+ hostNumLockState = false;
}
}
}
+ /* uppercase alphabet */
if (event->key() >= 65 && event->key() <= 90) {
#ifdef CONFIG_WIN32
if (event->nativeModifiers() & 256) {
#else
if (event->nativeModifiers() & 0x02) {
#endif
- capsLockState = ON;
+ hostCapsLockState = true;
} else {
- capsLockState = OFF;
+ hostCapsLockState = false;
}
}
changeCapsLockState();
#endif
- if (get_emul_num_lock_state() != numLockState) {
+ if (guestNumLockState != hostNumLockState) {
virtio_keyboard_event(69);
virtio_keyboard_event(69 | 0x80);
- set_emul_num_lock_state(get_emul_num_lock_state() ^ 1);
+ guestNumLockState = !guestNumLockState; /* toggle */
- qDebug() << "qemu NumLock state was synchronized with host key value (" <<
- get_emul_num_lock_state() << ")";
+ qDebug() << "NumLock state was synchronized:" << guestNumLockState;
}
int ret = keyCodeOperation(event, keyCode);
/* for auto release */
keyCodeList.append(ret);
do_qt_keyboard_key_event(KEY_PRESSED, ret);
+
#ifdef CONFIG_DARWIN
if ((event->modifiers() & Qt::ControlModifier) && event->nativeModifiers()) {
keyReleased(event);
/* NumLock or CapsLock key */
if (keyCode == Qt::Key_NumLock) {
- qDebug() << "num_lock state:" << numLockState << "released";
+ qDebug("num_lock released");
return;
} else if (keyCode == Qt::Key_CapsLock) {
+ qDebug("caps_lock released");
+
#ifdef CONFIG_DARWIN
- capsLockState = OFF;
+ hostCapsLockState = false;
changeCapsLockState();
#endif
- qDebug() << "caps_lock state:" << capsLockState << "released";
return;
}
#ifdef CONFIG_LINUX
/* for keypad keycode translation */
- if (numLockState && event->modifiers() == Qt::KeypadModifier) {
+ if (hostNumLockState && event->modifiers() == Qt::KeypadModifier) {
if (isSpecialKey(keyCode) || keyCode == Qt::Key_Clear) {
switch(keyCode) {
case Qt::Key_Delete: