AutoType: Finished X11 implementation for faked key press events from unicode chars (also with modifiers).
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@70 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
parent
c58dc2ab07
commit
9e8f6a336a
|
@ -21,37 +21,72 @@
|
||||||
#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;
|
||||||
|
|
||||||
void AutoType::perform(const QString& string){
|
int AutoType::getModifiers(Display *d,KeySym keysym, int keycode){
|
||||||
QList<QChar> Chars;
|
int SymsPerKey;
|
||||||
QString str("Fragezeichen ? Umlaute öäü Euro €");
|
KeySym* Syms=XGetKeyboardMapping(d,keycode,1,&SymsPerKey);
|
||||||
for(int i=0;i<str.length();i++){
|
int c=-1;
|
||||||
Chars << str.at(i);
|
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){
|
||||||
|
QString str=string;
|
||||||
|
//replace all {..} string templates
|
||||||
|
|
||||||
|
QList<Q_UINT16> Keys;
|
||||||
|
for(int i=0;i<str.length();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[] =
|
||||||
{
|
{
|
||||||
{ 0x01a1, 0x0104 }, /* Aogonek Ą LATIN CAPITAL LETTER A WITH OGONEK */
|
{ 0x01a1, 0x0104 }, /* Aogonek Ą LATIN CAPITAL LETTER A WITH OGONEK */
|
||||||
|
@ -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))
|
||||||
|
|
|
@ -23,6 +23,13 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#ifdef Q_WS_X11
|
||||||
|
#define XK_MISCELLANY
|
||||||
|
#define XK_XKB_KEYS
|
||||||
|
#include <X11/extensions/XTest.h>
|
||||||
|
#include <X11/keysymdef.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct tKeysymMap{
|
typedef struct tKeysymMap{
|
||||||
Q_UINT16 keysym;
|
Q_UINT16 keysym;
|
||||||
|
@ -35,7 +42,10 @@ public:
|
||||||
static void perform(const QString& KeePassAutoTypeString);
|
static void perform(const QString& KeePassAutoTypeString);
|
||||||
private:
|
private:
|
||||||
static tKeysymMap KeysymMap[];
|
static tKeysymMap KeysymMap[];
|
||||||
static unsigned long getKeysym(const QChar& unicode);
|
static Q_UINT16 getKeysym(const QChar& unicode);
|
||||||
|
static int getModifiers(Display*,KeySym,int);
|
||||||
|
static void pressModifiers(Display*,int,bool Press=true);
|
||||||
|
static void releaseModifiers(Display*,int);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -324,8 +324,6 @@ return true;
|
||||||
|
|
||||||
|
|
||||||
void KeepassMainWindow::OnFileNew(){
|
void KeepassMainWindow::OnFileNew(){
|
||||||
AutoType::perform("");
|
|
||||||
return;
|
|
||||||
if(FileOpen)
|
if(FileOpen)
|
||||||
if(!closeDatabase())return;
|
if(!closeDatabase())return;
|
||||||
CPasswordDialog dlg(this,"PasswordDlg",true,false,true);
|
CPasswordDialog dlg(this,"PasswordDlg",true,false,true);
|
||||||
|
|
Loading…
Reference in New Issue