|
|
@ -21,35 +21,70 @@ |
|
|
|
#include "AutoType.h" |
|
|
|
#include "AutoType.h" |
|
|
|
#include <QList> |
|
|
|
#include <QList> |
|
|
|
#include <QChar> |
|
|
|
#include <QChar> |
|
|
|
#ifdef Q_WS_X11 |
|
|
|
/* { 0x05c7, 0x0627 }, Arabic_alef ا ARABIC LETTER ALEF */ |
|
|
|
#include <X11/extensions/XTest.h> |
|
|
|
|
|
|
|
#include <X11/Xlib.h> |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QWidget* AutoType::MainWin=NULL;
|
|
|
|
QWidget* AutoType::MainWin=NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int AutoType::getModifiers(Display *d,KeySym keysym, int keycode){ |
|
|
|
|
|
|
|
int SymsPerKey; |
|
|
|
|
|
|
|
KeySym* Syms=XGetKeyboardMapping(d,keycode,1,&SymsPerKey); |
|
|
|
|
|
|
|
int c=-1; |
|
|
|
|
|
|
|
for(int i=0;i<4;i++) |
|
|
|
|
|
|
|
if(Syms[i]==keysym){ |
|
|
|
|
|
|
|
c=i; break;} |
|
|
|
|
|
|
|
Q_ASSERT(c!=-1); |
|
|
|
|
|
|
|
XFree(Syms); |
|
|
|
|
|
|
|
return c; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AutoType::releaseModifiers(Display* d,int mods){ |
|
|
|
|
|
|
|
pressModifiers(d,mods,False); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AutoType::pressModifiers(Display* d,int mods,bool press){ |
|
|
|
|
|
|
|
int keycode; |
|
|
|
|
|
|
|
switch(mods){ |
|
|
|
|
|
|
|
case 0: //no modifier
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 1: //Shift
|
|
|
|
|
|
|
|
XTestFakeKeyEvent(d,XKeysymToKeycode(d,XK_Shift_L),press,5); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 2: //AltGr
|
|
|
|
|
|
|
|
XTestFakeKeyEvent(d,XKeysymToKeycode(d,XK_ISO_Level3_Shift),press,5); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 3: //Shift+AltGr
|
|
|
|
|
|
|
|
XTestFakeKeyEvent(d,XKeysymToKeycode(d,XK_Shift_L),press,5); |
|
|
|
|
|
|
|
XTestFakeKeyEvent(d,XKeysymToKeycode(d,XK_ISO_Level3_Shift),press,5); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AutoType::perform(const QString& string){ |
|
|
|
void AutoType::perform(const QString& string){ |
|
|
|
QList<QChar> Chars; |
|
|
|
QString str=string; |
|
|
|
QString str("Fragezeichen ? Umlaute öäü Euro €"); |
|
|
|
//replace all {..} string templates
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<Q_UINT16> Keys; |
|
|
|
for(int i=0;i<str.length();i++){ |
|
|
|
for(int i=0;i<str.length();i++){ |
|
|
|
Chars << str.at(i); |
|
|
|
Keys << getKeysym(str.at(i)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MainWin->hide(); |
|
|
|
MainWin->hide(); |
|
|
|
|
|
|
|
|
|
|
|
Display* pDisplay = XOpenDisplay( NULL ); |
|
|
|
Display* pDisplay = XOpenDisplay( NULL ); |
|
|
|
for(int i=0;i<Chars.size();i++){ |
|
|
|
for(int i=0;i<Keys.size();i++){ |
|
|
|
XTestFakeKeyEvent(pDisplay,XKeysymToKeycode(pDisplay,getKeysym(Chars[i])),True,CurrentTime); |
|
|
|
int keycode=XKeysymToKeycode(pDisplay,Keys[i]); |
|
|
|
XTestFakeKeyEvent(pDisplay,XKeysymToKeycode(pDisplay,getKeysym(Chars[i])),False,CurrentTime); |
|
|
|
int mods=getModifiers(pDisplay,Keys[i],keycode); |
|
|
|
|
|
|
|
pressModifiers(pDisplay,mods); |
|
|
|
|
|
|
|
XTestFakeKeyEvent(pDisplay,keycode,True,5); |
|
|
|
|
|
|
|
XTestFakeKeyEvent(pDisplay,keycode,False,5); |
|
|
|
|
|
|
|
releaseModifiers(pDisplay,mods); |
|
|
|
} |
|
|
|
} |
|
|
|
XCloseDisplay(pDisplay); |
|
|
|
XCloseDisplay(pDisplay); |
|
|
|
|
|
|
|
MainWin->show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MainWin->show(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tKeysymMap AutoType::KeysymMap[] = |
|
|
|
tKeysymMap AutoType::KeysymMap[] = |
|
|
@ -829,10 +864,9 @@ tKeysymMap AutoType::KeysymMap[] = |
|
|
|
{ 0x20ac, 0x20ac }, /* EuroSign € EURO SIGN */ |
|
|
|
{ 0x20ac, 0x20ac }, /* EuroSign € EURO SIGN */ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
unsigned long AutoType::getKeysym(const QChar& c){ |
|
|
|
Q_UINT16 AutoType::getKeysym(const QChar& c){ |
|
|
|
int MapSize=sizeof(KeysymMap); |
|
|
|
int MapSize=sizeof(KeysymMap); |
|
|
|
Q_UINT16 unicode=c.unicode(); |
|
|
|
Q_UINT16 unicode=c.unicode(); |
|
|
|
|
|
|
|
|
|
|
|
/* first check for Latin-1 characters (1:1 mapping) */ |
|
|
|
/* first check for Latin-1 characters (1:1 mapping) */ |
|
|
|
if ((unicode >= 0x0020 && unicode <= 0x007e) || |
|
|
|
if ((unicode >= 0x0020 && unicode <= 0x007e) || |
|
|
|
(unicode >= 0x00a0 && unicode <= 0x00ff)) |
|
|
|
(unicode >= 0x00a0 && unicode <= 0x00ff)) |
|
|
|