trying to build keyboard

This commit is contained in:
Dustin Bensing 2013-07-16 23:08:00 +02:00
parent ea70f162ad
commit dafd37c4d6
11 changed files with 66 additions and 17 deletions

View File

@ -26,7 +26,7 @@ macx {
}
unix:!macx{
# linux only
LIBS += -lX11
LIBS += -lX11 -lXtst
}
win32 {
# windows only

View File

@ -50,8 +50,18 @@ int main()
waitABit();
sim.mouseScrollX(-10);
// char anA = 'a';
// cout << "a: " << (int)anA << " " << sim.charToKeyCode(anA) << endl;
// std::cout << std::endl;
// waitABit();
// sim.keyClick(sim.charToKeyCode(anA));
// std::cout << std::endl;
// waitABit();
// sim.keySequence(" Simple sentence Here 123 ");
waitABit();
//waitABit();
return 0;
}

View File

@ -75,9 +75,9 @@ void XInputSimulator::keyClick(int key)
implementation->keyClick(key);
}
void XInputSimulator::charToKeyCode(char key_char)
int XInputSimulator::charToKeyCode(char key_char)
{
implementation->charToKeyCode(key_char);
return implementation->charToKeyCode(key_char);
}
void XInputSimulator::keySequence(const std::string &sequence)

View File

@ -72,7 +72,7 @@ public:
void keyUp(int key);
void keyClick(int key);
void charToKeyCode(char key_char);
int charToKeyCode(char key_char);
void keySequence(const std::string &sequence);
// mouse

View File

@ -39,7 +39,7 @@ public:
virtual void keyUp(int key) = 0;
virtual void keyClick(int key) = 0;
virtual void charToKeyCode(char key_char) = 0;
virtual int charToKeyCode(char key_char) = 0;
virtual void keySequence(const std::string &sequence) = 0;
};

View File

@ -141,26 +141,63 @@ void XInputSimulatorImplLinux::mouseScrollY(int length)
void XInputSimulatorImplLinux::keyDown(int key)
{
throw NotImplementedException();
//throw NotImplementedException();
XTestFakeKeyEvent(display, key, True, 0);
XFlush(display);
}
void XInputSimulatorImplLinux::keyUp(int key)
{
throw NotImplementedException();
//throw NotImplementedException();
XTestFakeKeyEvent(display, key, False, 0);
XFlush(display);
}
void XInputSimulatorImplLinux::keyClick(int key)
{
throw NotImplementedException();
std::cout << "key click: " << key << std::endl;
//throw NotImplementedException();
this->keyDown(key);
this->keyUp(key);
}
void XInputSimulatorImplLinux::charToKeyCode(char key_char)
int XInputSimulatorImplLinux::charToKeyCode(char key_char)
{
throw NotImplementedException();
std::cout << "cchar: " << (int)key_char << std::endl;
//throw NotImplementedException();
// KeySym sym = XStringToKeysym(&key_char);
// std::cout << "sym: " << sym << std::endl;
int keyCode = XKeysymToKeycode(display, key_char);
std::cout << "ccode: " << keyCode << std::endl;
return keyCode;
}
void XInputSimulatorImplLinux::keySequence(const std::string &sequence)
{
throw NotImplementedException();
//throw NotImplementedException();
std::cout << "key seq: " << sequence << std::endl;
//c++11 training
// for(auto it = sequence.begin(); it != sequence.end(); ++it) {
// std::cout << "key org: " << (int)(*it) << std::endl;
// int keyCode = this->charToKeyCode(*it);
// std::cout << "key code: " << keyCode << std::endl;
// this->keyClick(keyCode);
// }
//c++11 better
for(const char c : sequence) {
std::cout << "cahr: " << c << std::endl;
int keyCode = this->charToKeyCode(c);
std::cout << "key code: " << keyCode << std::endl;
this->keyClick(keyCode);
std::cout << std::endl;
}
}

View File

@ -22,6 +22,8 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <X11/extensions/XTest.h>
#include "xinputsimulatorimpl.h"
@ -50,7 +52,7 @@ public:
virtual void keyUp(int key) override;
virtual void keyClick(int key) override;
virtual void charToKeyCode(char key_char) override;
virtual int charToKeyCode(char key_char) override;
virtual void keySequence(const std::string &sequence) override;
};

View File

@ -192,7 +192,7 @@ void XInputSimulatorImplMacOs::keyClick(int key)
throw NotImplementedException();
}
void XInputSimulatorImplMacOs::charToKeyCode(char key_char)
int XInputSimulatorImplMacOs::charToKeyCode(char key_char)
{
throw NotImplementedException();
}

View File

@ -47,7 +47,7 @@ public:
virtual void keyUp(int key) override;
virtual void keyClick(int key) override;
virtual void charToKeyCode(char key_char) override;
virtual int charToKeyCode(char key_char) override;
virtual void keySequence(const std::string &sequence) override;
};

View File

@ -149,7 +149,7 @@ void XInputSimulatorImplWin::keyClick(int key)
throw NotImplementedException();
}
void XInputSimulatorImplWin::charToKeyCode(char key_char)
int XInputSimulatorImplWin::charToKeyCode(char key_char)
{
throw NotImplementedException();
}

View File

@ -46,7 +46,7 @@ public:
virtual void keyUp(int key) override;
virtual void keyClick(int key) override;
virtual void charToKeyCode(char key_char) override;
virtual int charToKeyCode(char key_char) override;
virtual void keySequence(const std::string &sequence) override;
};