trying to build keyboard
This commit is contained in:
parent
ea70f162ad
commit
dafd37c4d6
|
@ -26,7 +26,7 @@ macx {
|
||||||
}
|
}
|
||||||
unix:!macx{
|
unix:!macx{
|
||||||
# linux only
|
# linux only
|
||||||
LIBS += -lX11
|
LIBS += -lX11 -lXtst
|
||||||
}
|
}
|
||||||
win32 {
|
win32 {
|
||||||
# windows only
|
# windows only
|
||||||
|
|
|
@ -50,8 +50,18 @@ int main()
|
||||||
waitABit();
|
waitABit();
|
||||||
sim.mouseScrollX(-10);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,9 +75,9 @@ void XInputSimulator::keyClick(int key)
|
||||||
implementation->keyClick(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)
|
void XInputSimulator::keySequence(const std::string &sequence)
|
||||||
|
|
|
@ -72,7 +72,7 @@ public:
|
||||||
void keyUp(int key);
|
void keyUp(int key);
|
||||||
void keyClick(int key);
|
void keyClick(int key);
|
||||||
|
|
||||||
void charToKeyCode(char key_char);
|
int charToKeyCode(char key_char);
|
||||||
void keySequence(const std::string &sequence);
|
void keySequence(const std::string &sequence);
|
||||||
|
|
||||||
// mouse
|
// mouse
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
virtual void keyUp(int key) = 0;
|
virtual void keyUp(int key) = 0;
|
||||||
virtual void keyClick(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;
|
virtual void keySequence(const std::string &sequence) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -141,26 +141,63 @@ void XInputSimulatorImplLinux::mouseScrollY(int length)
|
||||||
|
|
||||||
void XInputSimulatorImplLinux::keyDown(int key)
|
void XInputSimulatorImplLinux::keyDown(int key)
|
||||||
{
|
{
|
||||||
throw NotImplementedException();
|
//throw NotImplementedException();
|
||||||
|
XTestFakeKeyEvent(display, key, True, 0);
|
||||||
|
XFlush(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XInputSimulatorImplLinux::keyUp(int key)
|
void XInputSimulatorImplLinux::keyUp(int key)
|
||||||
{
|
{
|
||||||
throw NotImplementedException();
|
//throw NotImplementedException();
|
||||||
|
XTestFakeKeyEvent(display, key, False, 0);
|
||||||
|
XFlush(display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XInputSimulatorImplLinux::keyClick(int key)
|
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)
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
#include <X11/keysym.h>
|
||||||
|
#include <X11/extensions/XTest.h>
|
||||||
|
|
||||||
#include "xinputsimulatorimpl.h"
|
#include "xinputsimulatorimpl.h"
|
||||||
|
|
||||||
|
@ -50,7 +52,7 @@ public:
|
||||||
virtual void keyUp(int key) override;
|
virtual void keyUp(int key) override;
|
||||||
virtual void keyClick(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;
|
virtual void keySequence(const std::string &sequence) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -192,7 +192,7 @@ void XInputSimulatorImplMacOs::keyClick(int key)
|
||||||
throw NotImplementedException();
|
throw NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XInputSimulatorImplMacOs::charToKeyCode(char key_char)
|
int XInputSimulatorImplMacOs::charToKeyCode(char key_char)
|
||||||
{
|
{
|
||||||
throw NotImplementedException();
|
throw NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ public:
|
||||||
virtual void keyUp(int key) override;
|
virtual void keyUp(int key) override;
|
||||||
virtual void keyClick(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;
|
virtual void keySequence(const std::string &sequence) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -149,7 +149,7 @@ void XInputSimulatorImplWin::keyClick(int key)
|
||||||
throw NotImplementedException();
|
throw NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XInputSimulatorImplWin::charToKeyCode(char key_char)
|
int XInputSimulatorImplWin::charToKeyCode(char key_char)
|
||||||
{
|
{
|
||||||
throw NotImplementedException();
|
throw NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
virtual void keyUp(int key) override;
|
virtual void keyUp(int key) override;
|
||||||
virtual void keyClick(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;
|
virtual void keySequence(const std::string &sequence) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue