Compare commits
2 Commits
19d5be6dfc
...
0151c34bd2
Author | SHA1 | Date |
---|---|---|
mrbesen | 0151c34bd2 | |
Ahmad Fatoum | 7faf7dfc29 |
|
@ -87,16 +87,6 @@
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</file>
|
</file>
|
||||||
<file leaf-file-name="xinputsimulatorimpllinux.h" pinned="false" current-in-tab="false">
|
|
||||||
<entry file="file://$PROJECT_DIR$/xinputsimulatorimpllinux.h">
|
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
|
||||||
<state vertical-scroll-proportion="0.0">
|
|
||||||
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
|
|
||||||
<folding />
|
|
||||||
</state>
|
|
||||||
</provider>
|
|
||||||
</entry>
|
|
||||||
</file>
|
|
||||||
<file leaf-file-name="notimplementedexception.cpp" pinned="false" current-in-tab="false">
|
<file leaf-file-name="notimplementedexception.cpp" pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/notimplementedexception.cpp">
|
<entry file="file://$PROJECT_DIR$/notimplementedexception.cpp">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
@ -506,4 +496,4 @@
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,41 +1,93 @@
|
||||||
cmake_minimum_required(VERSION 2.8.4)
|
cmake_minimum_required(VERSION 2.8.4)
|
||||||
project(XInputSimulator)
|
project(XInputSimulator)
|
||||||
|
set(PROJECT_VERSION 0.1)
|
||||||
|
|
||||||
|
option(WITH_PIC "Compile static library as position-independent code" OFF) # Shared library is always PIC
|
||||||
|
option(BUILD_STATIC_LIBS "Build the static library" ON)
|
||||||
|
option(BUILD_SHARED_LIBS "Build the shared library" ON)
|
||||||
|
option(BUILD_MACOS_FATLIB "Build Fat library for both i386 and x86_64 on macOS" ON)
|
||||||
|
option(BUILD_MANUAL_TEST "Build the test application" ON)
|
||||||
|
|
||||||
|
if(BUILD_MACOS_FATLIB)
|
||||||
|
if (CMAKE_OSX_ARCHITECTURES)
|
||||||
|
message(FATAL_ERROR "User supplied -DCMAKE_OSX_ARCHITECTURES overrides BUILD_MACOS_FATLIB=ON")
|
||||||
|
else()
|
||||||
|
SET(CMAKE_OSX_ARCHITECTURES "x86_64;i386")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# Linux
|
# Linux
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
find_library(X_11 X11)
|
find_library(X_11 X11)
|
||||||
find_library(X_TST Xtst)
|
find_library(X_TST Xtst)
|
||||||
set(EXTRA_LIBS ${X_11} ${X_TST})
|
set(EXTRA_LIBS ${X_11} ${X_TST})
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
set(PLATFORM_SOURCE_FILES xinputsimulatorimpllinux.cpp xinputsimulatorimpllinux.h)
|
# Not nice, but I don't know how to have CMake generate all dependencies
|
||||||
|
# One could run ldd(1) on the .so and extract all deps...
|
||||||
|
set(PKG_CONFIG_EXTRA_LIBS "-lX11 -lXtst -lXext -lxcb -lXau -pthread -lXdmcp -lrt")
|
||||||
|
set(PLATFORM_SOURCE_FILES xinputsimulatorimpllinux.cpp xinputsimulatorimpllinux.h)
|
||||||
|
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
|
||||||
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
endif(UNIX AND NOT APPLE)
|
endif(UNIX AND NOT APPLE)
|
||||||
|
|
||||||
# Apple
|
# Apple
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
find_library(APP_SERVICES ApplicationServices)
|
|
||||||
find_library(CARBON Carbon)
|
find_library(CARBON Carbon)
|
||||||
find_library(CORE_FOUNDATION CoreFoundation)
|
find_library(CORE_FOUNDATION CoreFoundation)
|
||||||
set(EXTRA_LIBS ${APP_SERVICES_LIBRARY} ${CARBON} ${CORE_FOUNDATION})
|
set(EXTRA_LIBS ${CARBON} ${CORE_FOUNDATION})
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
set(PKG_CONFIG_EXTRA_LIBS "-framework CoreFoundation -framework Carbon")
|
||||||
set(PLATFORM_SOURCE_FILES xinputsimulatorimplmacos.cpp xinputsimulatorimplmacos.h)
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
set(PLATFORM_SOURCE_FILES xinputsimulatorimplmacos.cpp xinputsimulatorimplmacos.h)
|
||||||
|
set(CMAKE_MACOSX_RPATH ON)
|
||||||
endif(APPLE)
|
endif(APPLE)
|
||||||
|
|
||||||
# Windows
|
|
||||||
if(WIN32)
|
|
||||||
#find_library(USER_32 User32.Lib)
|
|
||||||
#set(EXTRA_LIBS ${USER_32})
|
|
||||||
set(PLATFORM_SOURCE_FILES xinputsimulatorimplwin.cpp xinputsimulatorimplwin.h)
|
|
||||||
endif(WIN32)
|
|
||||||
|
|
||||||
set(SOURCE_FILES
|
|
||||||
main.cpp
|
|
||||||
notimplementedexception.cpp
|
|
||||||
notimplementedexception.h
|
|
||||||
xinputsimulator.cpp
|
|
||||||
xinputsimulator.h
|
|
||||||
xinputsimulatorimpl.cpp
|
|
||||||
xinputsimulatorimpl.h
|
|
||||||
${PLATFORM_SOURCE_FILES})
|
|
||||||
|
|
||||||
add_executable(XInputSimulator ${SOURCE_FILES})
|
# Windows
|
||||||
target_link_libraries(XInputSimulator ${EXTRA_LIBS} )
|
if(WIN32)
|
||||||
|
#find_library(USER_32 User32.Lib)
|
||||||
|
#set(EXTRA_LIBS ${USER_32})
|
||||||
|
set(PLATFORM_SOURCE_FILES xinputsimulatorimplwin.cpp xinputsimulatorimplwin.h)
|
||||||
|
endif(WIN32)
|
||||||
|
|
||||||
|
set(SOURCE_FILES
|
||||||
|
notimplementedexception.cpp
|
||||||
|
xinputsimulator.cpp
|
||||||
|
xinputsimulator.h
|
||||||
|
xinputsimulatorimpl.cpp
|
||||||
|
xinputsimulatorimpl.h
|
||||||
|
${PLATFORM_SOURCE_FILES})
|
||||||
|
|
||||||
|
link_libraries(${EXTRA_LIBS} )
|
||||||
|
configure_file(XInputSimulator.pc.in XInputSimulator.pc @ONLY)
|
||||||
|
|
||||||
|
if (BUILD_SHARED_LIBS)
|
||||||
|
add_library(XInputSimulator SHARED ${SOURCE_FILES})
|
||||||
|
set_property(TARGET XInputSimulator PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||||
|
endif()
|
||||||
|
if (BUILD_STATIC_LIBS)
|
||||||
|
add_library(XInputSimulator_static STATIC ${SOURCE_FILES})
|
||||||
|
if (WITH_PIC)
|
||||||
|
set_property(TARGET XInputSimulator_static PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||||
|
endif()
|
||||||
|
if(NOT WIN32) # Keep lib*.(a|dll) name, but avoid *.lib files overwriting each other on Windows
|
||||||
|
set_target_properties(XInputSimulator_static PROPERTIES OUTPUT_NAME XInputSimulator)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
IF (NOT (BUILD_STATIC_LIBS OR BUILD_SHARED_LIBS))
|
||||||
|
MESSAGE(FATAL_ERROR "Both -DBUILD_SHARED_LIBS=OFF and -DBUILD_STATIC_LIBS=OFF supplied. Nothing to do...")
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
if (BUILD_MANUAL_TEST)
|
||||||
|
add_executable(XInputSimulator_bin main.cpp)
|
||||||
|
target_link_libraries(XInputSimulator_bin XInputSimulator)
|
||||||
|
set_target_properties(XInputSimulator_bin PROPERTIES OUTPUT_NAME "XInputSimulator")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
install(FILES ${CMAKE_BINARY_DIR}/XInputSimulator.pc DESTINATION lib/pkgconfig)
|
||||||
|
install(TARGETS XInputSimulator XInputSimulator_static
|
||||||
|
LIBRARY DESTINATION lib
|
||||||
|
ARCHIVE DESTINATION lib)
|
||||||
|
install(FILES xinputsimulator.h DESTINATION include)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
|
exec_prefix=${prefix}
|
||||||
|
libdir=${exec_prefix}/lib
|
||||||
|
includedir=${prefix}/include
|
||||||
|
|
||||||
|
Name: XInputSimulator
|
||||||
|
Description: Cross-Platform Simulator mouse and keyboard input
|
||||||
|
URL: https://github.com/pythoneer/XInputSimulator
|
||||||
|
Version: @PROJECT_VERSION@
|
||||||
|
Requires:
|
||||||
|
Libs: -L${libdir} -lXInputSimulator
|
||||||
|
Libs.private: @PKG_CONFIG_EXTRA_LIBS@
|
||||||
|
Cflags: -I${includedir}
|
||||||
|
|
|
@ -18,7 +18,6 @@ HEADERS += \
|
||||||
xinputsimulator.h \
|
xinputsimulator.h \
|
||||||
xinputsimulatorimpl.h \
|
xinputsimulatorimpl.h \
|
||||||
xinputsimulatorimpllinux.h \
|
xinputsimulatorimpllinux.h \
|
||||||
notimplementedexception.h \
|
|
||||||
xinputsimulatorimplmacos.h \
|
xinputsimulatorimplmacos.h \
|
||||||
xinputsimulatorimplwin.h
|
xinputsimulatorimplwin.h
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// You should have received a copy of the GNU Lesser Public License
|
// You should have received a copy of the GNU Lesser Public License
|
||||||
// along with XInputSimulator. If not, see <http://www.gnu.org/licenses/>.
|
// along with XInputSimulator. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "notimplementedexception.h"
|
#include "xinputsimulator.h"
|
||||||
|
|
||||||
NotImplementedException::NotImplementedException()
|
NotImplementedException::NotImplementedException()
|
||||||
:
|
:
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
// Copyright 2013 Dustin Bensing
|
|
||||||
|
|
||||||
// This file is part of XInputSimulator.
|
|
||||||
|
|
||||||
// XInputSimulator is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Lesser Public License as published by
|
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// any later version.
|
|
||||||
|
|
||||||
// XInputSimulator is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Lesser Public License for more details.
|
|
||||||
|
|
||||||
// You should have received a copy of the GNU Lesser Public License
|
|
||||||
// along with XInputSimulator. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
#ifndef NOTIMPLEMENTEDEXCEPTION_H
|
|
||||||
#define NOTIMPLEMENTEDEXCEPTION_H
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
class NotImplementedException : public std::runtime_error
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NotImplementedException();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // NOTIMPLEMENTEDEXCEPTION_H
|
|
|
@ -17,6 +17,32 @@
|
||||||
|
|
||||||
#include "xinputsimulator.h"
|
#include "xinputsimulator.h"
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
#include "xinputsimulatorimpllinux.h"
|
||||||
|
#elif __APPLE__
|
||||||
|
#include "xinputsimulatorimplmacos.h"
|
||||||
|
#elif _WIN32
|
||||||
|
#include "xinputsimulatorimplwin.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
XInputSimulator & XInputSimulator::getInstance()
|
||||||
|
{
|
||||||
|
static XInputSimulator instance;
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
instance.implementation = new XInputSimulatorImplLinux;
|
||||||
|
#elif __APPLE__
|
||||||
|
instance.implementation = new XInputSimulatorImplMacOs;
|
||||||
|
#elif _WIN32
|
||||||
|
instance.implementation = new XInputSimulatorImplWin;
|
||||||
|
#endif
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
XInputSimulator::~XInputSimulator() {
|
||||||
|
delete implementation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//*************************************************//
|
//*************************************************//
|
||||||
//******************M O U S E**********************//
|
//******************M O U S E**********************//
|
||||||
|
|
|
@ -20,21 +20,12 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "xinputsimulatorimpl.h"
|
#include <stdexcept>
|
||||||
#include "notimplementedexception.h"
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
#include "xinputsimulatorimpllinux.h"
|
|
||||||
#elif __APPLE__
|
|
||||||
#include "xinputsimulatorimplmacos.h"
|
|
||||||
#elif _WIN32
|
|
||||||
#include "xinputsimulatorimplwin.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class XInputSimulator
|
class XInputSimulator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
XInputSimulatorImpl *implementation;
|
class XInputSimulatorImpl *implementation;
|
||||||
|
|
||||||
XInputSimulator(){}
|
XInputSimulator(){}
|
||||||
|
|
||||||
|
@ -42,23 +33,9 @@ public:
|
||||||
XInputSimulator(XInputSimulator&) = delete;
|
XInputSimulator(XInputSimulator&) = delete;
|
||||||
void operator=(XInputSimulator&) = delete;
|
void operator=(XInputSimulator&) = delete;
|
||||||
|
|
||||||
~XInputSimulator() {
|
~XInputSimulator();
|
||||||
delete implementation;
|
|
||||||
}
|
|
||||||
|
|
||||||
static XInputSimulator & getInstance()
|
static XInputSimulator & getInstance();
|
||||||
{
|
|
||||||
static XInputSimulator instance;
|
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
instance.implementation = new XInputSimulatorImplLinux;
|
|
||||||
#elif __APPLE__
|
|
||||||
instance.implementation = new XInputSimulatorImplMacOs;
|
|
||||||
#elif _WIN32
|
|
||||||
instance.implementation = new XInputSimulatorImplWin;
|
|
||||||
#endif
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mouseMoveTo(int x, int y);
|
void mouseMoveTo(int x, int y);
|
||||||
void mouseMoveRelative(int x, int y);
|
void mouseMoveRelative(int x, int y);
|
||||||
|
@ -83,4 +60,12 @@ public:
|
||||||
|
|
||||||
typedef XInputSimulator XIS;
|
typedef XInputSimulator XIS;
|
||||||
|
|
||||||
|
|
||||||
|
class NotImplementedException : public std::runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NotImplementedException();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // XINPUTSIMULATOR_H
|
#endif // XINPUTSIMULATOR_H
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include <unistd.h> //usleep
|
#include <unistd.h> //usleep
|
||||||
|
|
||||||
#include "xinputsimulatorimpllinux.h"
|
#include "xinputsimulatorimpllinux.h"
|
||||||
#include "notimplementedexception.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
//memset
|
//memset
|
||||||
|
@ -28,6 +27,8 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
XInputSimulatorImplLinux::XInputSimulatorImplLinux()
|
XInputSimulatorImplLinux::XInputSimulatorImplLinux()
|
||||||
{
|
{
|
||||||
|
@ -157,44 +158,39 @@ void XInputSimulatorImplLinux::keyUp(int key)
|
||||||
|
|
||||||
void XInputSimulatorImplLinux::keyClick(int key)
|
void XInputSimulatorImplLinux::keyClick(int key)
|
||||||
{
|
{
|
||||||
std::cout << "key click: " << key << std::endl;
|
|
||||||
|
|
||||||
this->keyDown(key);
|
this->keyDown(key);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(25));
|
||||||
this->keyUp(key);
|
this->keyUp(key);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(36));
|
||||||
}
|
}
|
||||||
|
|
||||||
int XInputSimulatorImplLinux::charToKeyCode(char key_char)
|
int XInputSimulatorImplLinux::charToKeyCode(char key_char)
|
||||||
{
|
{
|
||||||
std::cout << "cchar: " << (int)key_char << std::endl;
|
// std::cout << "cchar: " << (int)key_char << std::endl;
|
||||||
|
|
||||||
int keyCode = XKeysymToKeycode(display, key_char);
|
int keyCode = XKeysymToKeycode(display, key_char);
|
||||||
// int keyCode = XKeysymToKeycode(display, XStringToKeysym(&key_char));
|
// int keyCode = XKeysymToKeycode(display, XStringToKeysym(&key_char));
|
||||||
std::cout << "ccode: " << keyCode << std::endl;
|
// std::cout << "ccode: " << keyCode << std::endl;
|
||||||
|
|
||||||
return keyCode;
|
return keyCode;
|
||||||
}
|
}
|
||||||
void XInputSimulatorImplLinux::keySequence(const std::string &sequence)
|
void XInputSimulatorImplLinux::keySequence(const std::string &sequence)
|
||||||
{
|
{
|
||||||
std::cout << "key seq: " << sequence << std::endl;
|
|
||||||
|
|
||||||
for(const char c : sequence) {
|
for(const char c : sequence) {
|
||||||
std::cout << "cahr: " << c << std::endl;
|
|
||||||
int keyCode = this->charToKeyCode(c);
|
int keyCode = this->charToKeyCode(c);
|
||||||
std::cout << "key code: " << keyCode << std::endl;
|
|
||||||
|
|
||||||
if (isupper(c)) {
|
if (isupper(c)) {
|
||||||
std::cout << "upper " << c << std::endl;
|
|
||||||
|
|
||||||
this->keyDown(XKeysymToKeycode(display, XK_Shift_L));
|
this->keyDown(XKeysymToKeycode(display, XK_Shift_L));
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(42));
|
||||||
this->keyClick(keyCode);
|
this->keyClick(keyCode);
|
||||||
|
|
||||||
this->keyUp(XKeysymToKeycode(display, XK_Shift_L));
|
this->keyUp(XKeysymToKeycode(display, XK_Shift_L));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->keyClick(keyCode);
|
this->keyClick(keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(35));
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
//sleep
|
//sleep
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "xinputsimulator.h"
|
||||||
#include "xinputsimulatorimplmacos.h"
|
#include "xinputsimulatorimplmacos.h"
|
||||||
#include "notimplementedexception.h"
|
|
||||||
|
|
||||||
//#include <QDebug>
|
//#include <QDebug>
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#include "xinputsimulator.h"
|
||||||
#include "xinputsimulatorimplwin.h"
|
#include "xinputsimulatorimplwin.h"
|
||||||
#include "notimplementedexception.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
Loading…
Reference in New Issue