Commit e0ee3669 authored by Anatoly Mihalchenko's avatar Anatoly Mihalchenko

Virtual keyboard improvement

parent ca020305
......@@ -299,6 +299,7 @@
<file>images/virtual.keyboard/41/right-active.png</file>
<file>images/virtual.keyboard/41/backspace.png</file>
<file>images/virtual.keyboard/41/capslock.png</file>
<file>images/virtual.keyboard/41/shift.png</file>
<file>images/virtual.keyboard/41/tab.png</file>
<file>images/virtual.keyboard/29/centre-passive.png</file>
<file>images/virtual.keyboard/29/left-passive.png</file>
......@@ -308,6 +309,7 @@
<file>images/virtual.keyboard/29/right-active.png</file>
<file>images/virtual.keyboard/29/backspace.png</file>
<file>images/virtual.keyboard/29/capslock.png</file>
<file>images/virtual.keyboard/29/shift.png</file>
<file>images/virtual.keyboard/29/tab.png</file>
<file>images/toolPalette/cacheTool.png</file>
<file>images/libpalette/FlashCategory.svg</file>
......
......@@ -57,4 +57,5 @@ UBKeyboardLocale** UBPlatformUtils::getKeyboardLayouts(int& nCount)
{
nCount = nKeyboardLayouts;
return keyboardLayouts;
}
\ No newline at end of file
}
......@@ -23,30 +23,82 @@ class QMainWindow;
#define SYMBOL_KEYS_COUNT 47
struct KEYCODE{
KEYCODE()
:symbol(0)
,code(0)
,modifier(0)
{}
KEYCODE(int _symbol)
:symbol(_symbol)
,code(0)
,modifier(0)
{}
KEYCODE(int _symbol,
unsigned char _code,
int _modifier)
:symbol(_symbol)
,code(_code)
,modifier(_modifier)
{}
bool empty() const
{
return symbol == 0;
}
int symbol;
unsigned char code;
int modifier;
};
struct KEYBT
{
const QChar symbol1;
const int code1;
const QChar symbol2;
const int code2;
KEYBT(unsigned int _symbol1,
unsigned int _symbol2):
symbol1(_symbol1),
code1(_symbol1),
symbol2(_symbol2),
code2(_symbol2){}
KEYBT(QChar _symbol1,
int _code1,
QChar _symbol2,
int _code2):
symbol1(_symbol1),
code1(_code1),
symbol2(_symbol2),
code2(_code2){}
};
QChar symbol1;
QChar symbol2;
bool capsLockSwitch;
int modifier1;
int modifier2;
KEYCODE codes[8];
KEYBT( QChar _symbol1,
QChar _symbol2,
bool _capsLockSwitch,
int _modifier1,
int _modifier2,
KEYCODE c1 = 0,
KEYCODE c2 = 0,
KEYCODE c3 = 0,
KEYCODE c4 = 0,
KEYCODE c5 = 0,
KEYCODE c6 = 0,
KEYCODE c7 = 0,
KEYCODE c8 = 0)
:symbol1(_symbol1)
,symbol2(_symbol2)
,capsLockSwitch(_capsLockSwitch)
,modifier1(_modifier1)
,modifier2(_modifier2)
{
codes[0] = c1;
codes[1] = c2;
codes[2] = c3;
codes[3] = c4;
codes[4] = c5;
codes[5] = c6;
codes[6] = c7;
codes[7] = c8;
}
~KEYBT()
{}
};
class UBKeyboardLocale
{
......@@ -63,7 +115,7 @@ struct KEYBT
const QString& _name,
const QString& _id,
QIcon* _icon,
const KEYBT _symbols[])
KEYBT _symbols[])
:fullName(_fullName),name(_name), id(_id), icon(_icon),
constSymbols(_symbols), varSymbols(NULL)
{}
......@@ -74,12 +126,12 @@ struct KEYBT
const QString name;
const QString id;
QIcon* icon;
const KEYBT* operator[] (int index) const
KEYBT* operator[] (int index) const
{
return (varSymbols==NULL)? constSymbols + index : varSymbols[index];
}
private:
const KEYBT* constSymbols;
KEYBT* constSymbols;
KEYBT** varSymbols;
};
......
This diff is collapsed.
......@@ -10,8 +10,12 @@
#import <Foundation/NSAutoreleasePool.h>
#import <Carbon/Carbon.h>
#import <APELite.h>
/*
// commented because Sankore crashes on Java Script. It seems to backends dependencies.
#import <WebKit/WebKit.h>
#import <AppKit/AppKit.h>
*/
NSString* bundleShortVersion(NSBundle *bundle)
......@@ -409,14 +413,15 @@ KEYBT* createKeyBt(const UCKeyboardLayout* keyLayout, int vkk)
UInt32 deadKeyState = 0L;
UInt32 kbdType = kKeyboardISO;
UniCharCount cnt1, cnt2;
UniChar unicodeString1[100], unicodeString2[100];
UniCharCount cnt1, cnt2, cnt3;
UniChar unicodeString1[100], unicodeString2[100], unicodeString3[100];
UCKeyTranslate(keyLayout, vkk, kUCKeyActionDisplay, 0, kbdType, kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 100, &cnt1, unicodeString1);
UCKeyTranslate(keyLayout, vkk, kUCKeyActionDisplay, (shiftKey >> 8) & 0xff, kbdType, kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 100, &cnt2, unicodeString2);
UCKeyTranslate(keyLayout, vkk, kUCKeyActionDisplay, (alphaLock >> 8) & 0xff, kbdType, kUCKeyTranslateNoDeadKeysBit, &deadKeyState, 100, &cnt2, unicodeString3);
return new KEYBT(unicodeString1[0], vkk, unicodeString2[0], vkk);
}
return new KEYBT(unicodeString1[0], unicodeString2[0], unicodeString1[0] != unicodeString3[0], 0,0, KEYCODE(0, vkk, 0), KEYCODE(0, vkk, 1));
}
void UBPlatformUtils::initializeKeyboardLayouts()
......@@ -543,13 +548,14 @@ void UBPlatformUtils::destroyKeyboardLayouts()
QString UBPlatformUtils::urlFromClipboard()
{
QString qsRet;
/*
// commented because Sankore crashes on Java Script. It seems to backends dependencies.
NSPasteboard* pPasteboard = [NSPasteboard pasteboardWithName:@"Apple CFPasteboard drag"];
WebArchive* pArchive = [[WebArchive alloc] initWithData:[pPasteboard dataForType:@"com.apple.webarchive"]];
qsRet = [[[[pArchive mainResource] URL] absoluteString] UTF8String];
[pArchive release];
*/
return qsRet;
}
This diff is collapsed.
......@@ -38,11 +38,16 @@ UBKeyboardPalette::UBKeyboardPalette(QWidget *parent)
setGrip(false);
capsLock = false;
shift = false;
languagePopupActive = false;
keyboardActive = false;
nSpecialModifierIndex = 0;
specialModifier = 0;
btnWidth = btnHeight = 16;
strSize = "16x16";
currBtnImages = new BTNImages("16", btnWidth, btnHeight);
storage = NULL;
buttons = new UBKeyButton*[47];
for (int i=0; i<47; i++)
......@@ -77,7 +82,7 @@ void UBKeyboardPalette::init()
//------------------------------//
UBPlatformUtils::setWindowNonActivableFlag(this, true);
UBPlatformUtils::setWindowNonActivableFlag(this, true);
}
void UBKeyboardPalette::showKeyboard(bool show)
......@@ -143,6 +148,8 @@ UBKeyboardPalette::~UBKeyboardPalette()
delete currBtnImages;
currBtnImages = NULL;
}
onActivated(false);
}
QSize UBKeyboardPalette::sizeHint () const
......@@ -302,8 +309,10 @@ void UBKeyboardPalette::paintEvent( QPaintEvent* event)
//-------------------
// // Row 3 Stub
// ctrlButtons[ctrlButtonsId++]->setGeometry(offX, offY, btnWidth, btnHeight);
// offX += btnWidth;
// button Enter
ctrlButtons[ctrlButtonsId++]->setGeometry(offX, offY, btnWidth * 1, btnHeight);
offX += btnWidth*1;
// buttons [a]..[\]
for (int i = 0; i < 12; i++)
......@@ -313,8 +322,8 @@ void UBKeyboardPalette::paintEvent( QPaintEvent* event)
}
// button Enter
ctrlButtons[ctrlButtonsId++]->setGeometry(offX, offY, btnWidth * 3, btnHeight);
offX += btnWidth*3;
ctrlButtons[ctrlButtonsId++]->setGeometry(offX, offY, btnWidth * 2, btnHeight);
offX += btnWidth*2;
//------------------------------------------------
// set geometry (position) for row 4
......@@ -353,6 +362,11 @@ void UBKeyboardPalette::paintEvent( QPaintEvent* event)
//------------------------------------------------
}
void UBKeyboardPalette::onDeactivated()
{
onActivated(false);
}
//-----------------------------------------------------------------------//
// BTNImages Class
......@@ -415,6 +429,11 @@ UBKeyboardButton::~UBKeyboardButton()
}
}
bool UBKeyboardButton::isPressed()
{
return bPressed;
}
void UBKeyboardButton::paintEvent(QPaintEvent*)
{
......@@ -437,7 +456,7 @@ void UBKeyboardButton::paintEvent(QPaintEvent*)
//--------------------------
if (bPressed)
if (isPressed())
{
painter.drawImage( 0,0, m_parent->currBtnImages->m_btnLeftActive, 0,0, m_parent->currBtnImages->m_btnLeftActive.width(), m_parent->currBtnImages->m_btnLeftActive.height() );
painter.drawImage( QRect(m_parent->currBtnImages->m_btnLeftActive.width(), 0, width() - m_parent->currBtnImages->m_btnLeftActive.width() - m_parent->currBtnImages->m_btnRightActive.width(), height()), m_parent->currBtnImages->m_btnCenterActive );
......@@ -471,7 +490,7 @@ void UBKeyboardButton::leaveEvent ( QEvent*)
void UBKeyboardButton::mousePressEvent ( QMouseEvent * event)
{
event->accept();
event->accept();
bPressed = true;
update();
this->onPress();
......@@ -492,10 +511,55 @@ UBKeyButton::UBKeyButton(UBKeyboardPalette* parent)
UBKeyButton::~UBKeyButton()
{}
bool UBKeyButton::shifted()
{
bool b = keyboard->shift;
if (keybt->capsLockSwitch && keyboard->capsLock)
b = !b;
return b;
}
void UBKeyButton::onPress()
{
if (keybt!=NULL)
sendUnicodeSymbol(keybt->code1, keybt->code2, capsLock());
{
int codeIndex = keyboard->nSpecialModifierIndex * 2 + shifted();
if (keyboard->nSpecialModifierIndex)
{
if (keybt->codes[codeIndex].empty())
{
sendUnicodeSymbol(keyboard->specialModifier);
sendUnicodeSymbol(keybt->codes[shifted()]);
}
else
{
sendUnicodeSymbol(keybt->codes[codeIndex]);
}
keyboard->nSpecialModifierIndex = 0;
}
else
{
int nSpecialModifierIndex = shifted()? keybt->modifier2 : keybt->modifier1;
if (nSpecialModifierIndex)
{
keyboard->nSpecialModifierIndex = nSpecialModifierIndex;
keyboard->specialModifier = keybt->codes[codeIndex];
}
else
{
sendUnicodeSymbol(keybt->codes[codeIndex]);
}
}
}
if (keyboard->shift)
{
keyboard->shift = false;
keyboard->update();
}
}
void UBKeyButton::onRelease()
......@@ -505,7 +569,7 @@ void UBKeyButton::paintContent(QPainter& painter)
{
if (keybt)
{
QString text(QChar(capsLock() ? keybt->symbol2 : keybt->symbol1));
QString text(QChar(shifted() ? keybt->symbol2 : keybt->symbol1));
QRect textRect(rect().x()+2, rect().y()+2, rect().width()-4, rect().height()-4);
painter.drawText(textRect, Qt::AlignCenter, text);
}
......@@ -565,6 +629,11 @@ void UBCapsLockButton::onPress()
void UBCapsLockButton::onRelease()
{}
bool UBCapsLockButton::isPressed()
{
return keyboard->capsLock;
}
void UBCapsLockButton::paintContent(QPainter& painter)
{
if(imgContent != NULL)
......@@ -576,6 +645,40 @@ void UBCapsLockButton::paintContent(QPainter& painter)
painter.drawText(rect(), Qt::AlignCenter, "^");
}
UBShiftButton::UBShiftButton(UBKeyboardPalette* parent, const QString _contentImagePath)
:UBKeyboardButton(parent, _contentImagePath)
{}
UBShiftButton::~UBShiftButton()
{}
void UBShiftButton::onPress()
{
keyboard->shift = !keyboard->shift;
keyboard->update();
}
void UBShiftButton::onRelease()
{}
bool UBShiftButton::isPressed()
{
return keyboard->shift;
}
void UBShiftButton::paintContent(QPainter& painter)
{
if(imgContent != NULL)
{
painter.drawImage(( rect().width() - imgContent->m_btnContent.width() ) / 2, ( rect().height() - imgContent->m_btnContent.height() ) / 2,
imgContent->m_btnContent, 0,0, imgContent->m_btnContent.width(), imgContent->m_btnContent.height());
}
else
painter.drawText(rect(), Qt::AlignCenter, "^");
}
UBLocaleButton::UBLocaleButton(UBKeyboardPalette* parent)
:UBKeyboardButton(parent)
......
......@@ -64,7 +64,9 @@ class UBKeyboardPalette : public UBActionPalette
friend class UBKeyboardButton;
friend class UBCapsLockButton;
friend class UBShiftButton;
friend class UBLocaleButton;
friend class UBKeyButton;
public:
UBKeyboardPalette(QWidget *parent);
......@@ -97,10 +99,14 @@ private slots:
protected:
bool capsLock;
bool shift;
int nCurrentLocale;
int nLocalesCount;
UBKeyboardLocale** locales;
int nSpecialModifierIndex;
KEYCODE specialModifier;
QString strSize;
int btnWidth;
int btnHeight;
......@@ -113,7 +119,7 @@ protected:
virtual void paintEvent(QPaintEvent *event);
virtual void moveEvent ( QMoveEvent * event );
void sendKeyEvent(const KEYBT& keybt);
void sendKeyEvent(KEYCODE keyCode);
void setLocale(int nLocale);
......@@ -170,11 +176,11 @@ protected:
virtual void onRelease() = 0;
virtual void paintContent(QPainter& painter) = 0;
bool capsLock(){return keyboard->capsLock;}
virtual bool isPressed();
UBKeyboardPalette* keyboard;
void sendUnicodeSymbol(unsigned int nSymbol1, unsigned int nSymbol2, bool shift);
void sendUnicodeSymbol(KEYCODE keycode);
void sendControlSymbol(int nSymbol);
private:
......@@ -197,6 +203,7 @@ public:
virtual void paintContent(QPainter& painter);
private:
bool shifted();
const KEYBT* keybt;
};
......@@ -229,8 +236,28 @@ public:
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
protected:
virtual bool isPressed();
};
class UBShiftButton : public UBKeyboardButton
{
Q_OBJECT
public:
UBShiftButton(UBKeyboardPalette* parent, const QString _contentImagePath);
~UBShiftButton();
virtual void onPress();
virtual void onRelease();
virtual void paintContent(QPainter& painter);
protected:
virtual bool isPressed();
};
class UBLocaleButton : public UBKeyboardButton
{
Q_OBJECT
......
......@@ -70,22 +70,59 @@ void x11SendKey(Display *display, int keyCode, int modifiers)
// Send a fake key release event to the window.
event = createKeyEvent(display, winFocus, winRoot, false, keyCode, modifiers);
XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
}
void UBKeyboardButton::sendUnicodeSymbol(unsigned int nSymbol1, unsigned int nSymbol2, bool shift)
void traceKeyCodes()
{
unsigned int nSymbol = shift ? nSymbol2 : nSymbol1;
Display *display = XOpenDisplay(0);
if(display == NULL)
return;
int min_keycodes, max_keycodes, byte_per_code;
XDisplayKeycodes(display, &min_keycodes, &max_keycodes);
KeySym* keySyms = XGetKeyboardMapping(display, min_keycodes,
max_keycodes - min_keycodes, &byte_per_code);
qDebug() << "Codes table, min_keycodes: " << min_keycodes << ", max_keycodes: "
<< max_keycodes << ", bytes_per_code:" << byte_per_code;
for(int i=0; i<max_keycodes - min_keycodes; i++)
{
QString str;
for(int j=0; j<byte_per_code;j++)
{
str += QString::number(keySyms[i*byte_per_code + j], 16);
str += ":";
}
qDebug() << i << ":" << str;
}
XFree(keySyms);
XCloseDisplay(display);
}
void UBKeyboardButton::sendUnicodeSymbol(KEYCODE keycode)
{
// Obtain the X11 display.
Display *display = XOpenDisplay(0);
if(display == NULL)
return;
KeyCode keyCode = XKeysymToKeycode(display, nSymbol);
if (keyCode != NoSymbol)
if (!keycode.empty())
{
x11SendKey(display, keyCode, shift);
int modifier = keycode.modifier;
if (keycode.modifier==2) modifier = 0x2000;
if (keycode.modifier==3) modifier = 0x2001;
if (keycode.modifier==4) modifier = 0x4000;
if (keycode.modifier==5) modifier = 0x4001;
//modifiers 6 and 7 seems are not available.... They are reassigned in layout creationtime
//if (keycode.modifier==6) modifier = 0x6000;
//if (keycode.modifier==7) modifier = 0x6001;
x11SendKey(display, keycode.code + keyboard->min_keycodes , modifier);
}
XCloseDisplay(display);
......@@ -111,16 +148,17 @@ void UBKeyboardButton::sendControlSymbol(int nSymbol)
void UBKeyboardPalette::createCtrlButtons()
{
ctrlButtons = new UBKeyboardButton*[8];
ctrlButtons[0] = new UBCntrlButton(this, "<-", XK_BackSpace);
ctrlButtons[1] = new UBCntrlButton(this, "<->", XK_Tab);
ctrlButtons[2] = new UBCntrlButton(this, tr("Enter"), XK_Return);
ctrlButtons[3] = new UBCapsLockButton(this, "capslock");
ctrlButtons[4] = new UBCapsLockButton(this, "capslock");
ctrlButtons[5] = new UBLocaleButton(this);
ctrlButtons[6] = new UBCntrlButton(this, "", XK_space);
ctrlButtons[7] = new UBLocaleButton(this);
ctrlButtons = new UBKeyboardButton*[9];
ctrlButtons[0] = new UBCntrlButton(this, XK_BackSpace, "backspace");
ctrlButtons[1] = new UBCntrlButton(this, XK_Tab, "tab");
ctrlButtons[2] = new UBCapsLockButton(this, "capslock");
ctrlButtons[3] = new UBCntrlButton(this, tr("Enter"), XK_Return);
ctrlButtons[4] = new UBShiftButton(this, "shift");
ctrlButtons[5] = new UBShiftButton(this, "shift");
ctrlButtons[6] = new UBLocaleButton(this);
ctrlButtons[7] = new UBCntrlButton(this, "", XK_space);
ctrlButtons[8] = new UBLocaleButton(this);
}
......@@ -128,90 +166,114 @@ void UBKeyboardPalette::onActivated(bool activated)
{
if (activated)
{
if (storage)
{
qDebug() << "Keybard already activated....";
return;
}
Display *display = XOpenDisplay(0);
if(display == NULL)
return;
XDisplayKeycodes(display, &this->min_keycodes, &this->max_keycodes);
KeySym* keySyms = XGetKeyboardMapping(display, min_keycodes,
max_keycodes - min_keycodes, &this->byte_per_code);
max_keycodes - min_keycodes, &byte_per_code);
storage = keySyms;
XCloseDisplay(display);
qDebug() << "------------ ORIGINAL --------------------------------------------------";
traceKeyCodes();
onLocaleChanged(locales[nCurrentLocale]);
qDebug() << "------------ CUSTOM ------------------------------------------------";
traceKeyCodes();
qDebug() << "----------------------------------------------------------------------";
}
else
{
Display *display = XOpenDisplay(0);
if(display == NULL)
return;
{
qDebug() << "Keybard not activated....";
return;
}
KeySym* keySyms = (KeySym*)storage;
if (keySyms!=NULL)
{
qDebug() << "Default key table restored.....";
XChangeKeyboardMapping(display, min_keycodes, byte_per_code,
keySyms, max_keycodes - min_keycodes);
XFree(keySyms);
}
storage = NULL;
}
XCloseDisplay(display);
}
}
void UBKeyboardPalette::onDeactivated()
void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale)
{
Display *display = XOpenDisplay(0);
if(display == NULL)
return;
KeySym* keySyms = (KeySym*)storage;
if (keySyms!=NULL) {
XChangeKeyboardMapping(display, min_keycodes, byte_per_code,
keySyms, max_keycodes - min_keycodes);
}
XCloseDisplay(display);
}
int byte_per_code;
KeySym* keySyms = XGetKeyboardMapping(display, min_keycodes,
max_keycodes - min_keycodes, &byte_per_code);
void setSymbolsFromButton(Display *display,
const UBKeyboardLocale& locale,
int byte_per_code,
int nFromSymbol,
int nFromButton,
int count)
{
KeySym* keySyms = new KeySym[count * byte_per_code];
for(int i = 0; i < count; i++)
for(int i=0; i<SYMBOL_KEYS_COUNT; i++)
{
keySyms[byte_per_code * i + 0] =
keySyms[byte_per_code * i + 2] = locale[nFromButton + i]->code1;
keySyms[byte_per_code * i + 1] =
keySyms[byte_per_code * i + 3] = locale[nFromButton + i]->code2;
for(int j=4; j<byte_per_code; j++)
keySyms[byte_per_code * i + j] = NoSymbol;
// loop by keybt
for(int j=0; j<8; j++)
{
KEYCODE& kc = (*locale)[i]->codes[j];
if (!kc.empty())
{
if (kc.modifier <= 5)
keySyms[kc.code * byte_per_code + kc.modifier] = kc.symbol;
}
}
}
XChangeKeyboardMapping(display, nFromSymbol, byte_per_code, keySyms, count);
delete [] keySyms;
}
//Now look for modifiers > 5 and reassign them to free places
for(int i=0; i<SYMBOL_KEYS_COUNT; i++)
{
// loop by keybt
for(int j=0; j<8; j++)
{
KEYCODE& kc = (*locale)[i]->codes[j];
if (!kc.empty())
{
if (kc.modifier > 5)
{
for(int i1=0; i1<SYMBOL_KEYS_COUNT; i1++)
for(int j1=0; j1<=5; j1++)
if (keySyms[i1 * byte_per_code + j1]==NoSymbol)
{
kc.code =i1;
kc.modifier =j1;
break;
}
}
keySyms[kc.code * byte_per_code + kc.modifier] = kc.symbol;
}
}
}
void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale)
{
Display *display = XOpenDisplay(0);
if(display == NULL)
return;
setSymbolsFromButton(display, *locale, byte_per_code, min_keycodes + 41, 0, 1);
setSymbolsFromButton(display, *locale, byte_per_code, min_keycodes + 2, 1, 12);
setSymbolsFromButton(display, *locale, byte_per_code, min_keycodes + 16, 13, 12);
setSymbolsFromButton(display, *locale, byte_per_code, min_keycodes + 30, 25, 11);
setSymbolsFromButton(display, *locale, byte_per_code, min_keycodes + 44, 37, 10);
XChangeKeyboardMapping(display, min_keycodes, byte_per_code, keySyms, max_keycodes - min_keycodes);
XFree(keySyms);
XCloseDisplay(display);
}
......@@ -22,15 +22,13 @@
#include <QMap>
#include <QString>
void UBKeyboardButton::sendUnicodeSymbol(unsigned int nSymbol1, unsigned int nSymbol2, bool shift)
void UBKeyboardButton::sendUnicodeSymbol(KEYCODE keycode)
{
unsigned int nSymbol = (shift)? nSymbol2 : nSymbol1;
if (shift)
if (keycode.modifier)
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, 56, true));
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, nSymbol, true));
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, nSymbol, false));
if (shift)
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, keycode.code, true));
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, keycode.code, false));
if (keycode.modifier)
CGEventPost(kCGSessionEventTap, CGEventCreateKeyboardEvent(NULL, 56, false));
}
......@@ -46,16 +44,17 @@ void UBKeyboardButton::sendControlSymbol(int nSymbol)
void UBKeyboardPalette::createCtrlButtons()
{
ctrlButtons = new UBKeyboardButton*[7];
ctrlButtons = new UBKeyboardButton*[9];
ctrlButtons[0] = new UBCntrlButton(this, "<-", 51);
ctrlButtons[1] = new UBCntrlButton(this, "<->", 48);
ctrlButtons[2] = new UBCntrlButton(this, tr("Enter"), 76);
ctrlButtons[3] = new UBCapsLockButton(this, "capslock");
ctrlButtons[4] = new UBCapsLockButton(this, "capslock");
ctrlButtons[5] = new UBLocaleButton(this);
ctrlButtons[6] = new UBCntrlButton(this, "", 49);
ctrlButtons[7] = new UBLocaleButton(this);
ctrlButtons[0] = new UBCntrlButton(this, 51, "backspace");
ctrlButtons[1] = new UBCntrlButton(this, 48, "tab");
ctrlButtons[2] = new UBCapsLockButton(this, "capslock");
ctrlButtons[3] = new UBCntrlButton(this, tr("Enter"), 76);
ctrlButtons[4] = new UBShiftButton(this, "shift");
ctrlButtons[5] = new UBShiftButton(this, "shift");
ctrlButtons[6] = new UBLocaleButton(this);
ctrlButtons[7] = new UBCntrlButton(this, "", 49);
ctrlButtons[8] = new UBLocaleButton(this);
}
void SetMacLocaleByIdentifier(const QString& id)
......@@ -102,10 +101,7 @@ void UBKeyboardPalette::onActivated(bool activated)
SetMacLocaleByIdentifier(activeLocale);
}
}
void UBKeyboardPalette::onDeactivated()
{
SetMacLocaleByIdentifier(activeLocale);
}
void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale)
{
SetMacLocaleByIdentifier(locale->id);
......
......@@ -8,21 +8,19 @@
#include "core/memcheck.h"
void UBKeyboardButton::sendUnicodeSymbol(unsigned int nSymbol1, unsigned int nSymbol2, bool shift)
void UBKeyboardButton::sendUnicodeSymbol(KEYCODE keycode)
{
unsigned int nSymbol = shift? nSymbol2 : nSymbol1;
INPUT input[2];
input[0].type = INPUT_KEYBOARD;
input[0].ki.wVk = 0;
input[0].ki.wScan = nSymbol;
input[0].ki.wScan = keycode.symbol;
input[0].ki.dwFlags = KEYEVENTF_UNICODE;
input[0].ki.time = 0;
input[0].ki.dwExtraInfo = 0;
input[1].type = INPUT_KEYBOARD;
input[1].ki.wVk = 0;
input[1].ki.wScan = nSymbol;
input[1].ki.wScan = keycode.symbol;
input[1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
input[1].ki.time = 0;
input[1].ki.dwExtraInfo = 0;
......@@ -57,11 +55,10 @@ void UBKeyboardPalette::createCtrlButtons()
ctrlButtons[ctrlID++] = new UBCntrlButton(this, 0x08, "backspace");// Backspace
ctrlButtons[ctrlID++] = new UBCntrlButton(this, 0x09, "tab"); // Tab
// ctrlButtons[ctrlID++] = new UBKeyButton(this); // Row 2 Stub
// ctrlButtons[ctrlID++] = new UBKeyButton(this); // Row 3 Stub
ctrlButtons[ctrlID++] = new UBCapsLockButton(this, "capslock"); // Shift
ctrlButtons[ctrlID++] = new UBCntrlButton(this, tr("Enter"), 0x0d); // Enter
ctrlButtons[ctrlID++] = new UBCapsLockButton(this, "capslock"); // Caps Lock
ctrlButtons[ctrlID++] = new UBCapsLockButton(this, "capslock"); // Caps Lock
ctrlButtons[ctrlID++] = new UBShiftButton(this, "shift"); // Shift
ctrlButtons[ctrlID++] = new UBShiftButton(this, "shift"); // Shift
ctrlButtons[ctrlID++] = new UBLocaleButton(this); // Language Switch
ctrlButtons[ctrlID++] = new UBCntrlButton(this, "", 0x20); // Space
ctrlButtons[ctrlID++] = new UBLocaleButton(this); // Language Switch
......@@ -69,10 +66,6 @@ void UBKeyboardPalette::createCtrlButtons()
void UBKeyboardPalette::onActivated(bool)
{
}
void UBKeyboardPalette::onDeactivated()
{
}
void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* )
{}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment