XInputSimulator/XInputSimulator/main.cpp

93 lines
2.1 KiB
C++
Raw Normal View History

2013-07-14 14:25:29 +02:00
// 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
2013-07-14 14:28:53 +02:00
// any later version.
2013-07-14 14:25:29 +02:00
// 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/>.
2013-07-14 11:06:19 +02:00
#include <iostream>
2013-07-14 13:52:02 +02:00
#include "xinputsimulator.h"
2013-07-14 11:06:19 +02:00
2015-02-20 21:03:24 +01:00
#ifdef __linux__
//sleep
2013-07-15 16:14:20 +02:00
#include <unistd.h>
2015-02-20 21:03:24 +01:00
#elif __APPLE__
//sleep
#include <unistd.h>
#elif _WIN32
//sleep
#include <windows.h>
#endif
2013-07-14 11:06:19 +02:00
using namespace std;
void waitABit();
2013-07-14 11:06:19 +02:00
int main()
{
cout << "Hello World!" << endl;
2013-07-14 13:52:02 +02:00
XInputSimulator &sim = XInputSimulator::getInstance();
waitABit();
2015-02-15 22:45:12 +01:00
sim.mouseMoveTo(500,400);
waitABit();
sim.mouseMoveRelative(400, -100);
waitABit();
sim.mouseDown(XIS::LEFT_MOUSE_BUTTON);
waitABit();
sim.mouseMoveRelative(0, 300);
waitABit();
sim.mouseUp(XIS::LEFT_MOUSE_BUTTON);
waitABit();
//scroll down and up
sim.mouseScrollY(10);
waitABit();
sim.mouseScrollY(-10);
//scroll left and right
waitABit();
sim.mouseScrollX(10);
waitABit();
sim.mouseScrollX(-10);
2015-02-20 21:03:24 +01:00
#ifdef __linux__ || __APPLE__
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 ");
2015-02-20 21:03:24 +01:00
#elif _WIN32
//not implemented
#endif
2013-07-15 16:14:20 +02:00
2013-07-16 23:08:00 +02:00
2015-02-20 21:03:24 +01:00
waitABit();
2013-07-14 11:06:19 +02:00
return 0;
}
void waitABit()
{
2013-07-15 16:14:20 +02:00
//std::this_thread::sleep_for(std::chrono::milliseconds(1000));
2015-02-20 21:03:24 +01:00
#ifdef __linux__
sleep(1);
#elif __APPLE__
sleep(1);
#elif _WIN32
Sleep(1000);
#endif
}