85 lines
2.6 KiB
C++
85 lines
2.6 KiB
C++
|
|
#include <iostream>
|
|
#include <jstick.hpp>
|
|
#include <thread>
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
int main() {
|
|
bool success = jstick::Initialize();
|
|
|
|
if (!success) {
|
|
std::cerr << "Could not initialize jstick!" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
if (!jstick::JoystickDetected()) {
|
|
std::cerr << "No devices detected!" << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
int hwid = jstick::Connect(0);
|
|
|
|
while (jstick::JoystickDetected()) {
|
|
jstick::ReadEventLoop();
|
|
|
|
|
|
// Vibrate the joystick device by how much the thumbsticks are moved.
|
|
Vector2 axisL = jstick::GetLeftThumbstickAxis();
|
|
Vector2 axisR = jstick::GetRightThumbstickAxis();
|
|
|
|
jstick::Vibrate(axisL.Magnitude(), axisR.Magnitude());
|
|
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::Back))
|
|
std::cout << "Back Button Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::Start))
|
|
std::cout << "Start Button Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::ButtonA))
|
|
std::cout << "A Button Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::ButtonB))
|
|
std::cout << "B Button Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::ButtonX))
|
|
std::cout << "X Button Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::ButtonY))
|
|
std::cout << "Y Button Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::BumperL))
|
|
std::cout << "Left Bumper Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::BumperR))
|
|
std::cout << "Right Bumper Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::ThumbL))
|
|
std::cout << "Left Thumb Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::ThumbR))
|
|
std::cout << "Right Thumb Pressed" << std::endl;
|
|
|
|
if (!jstick::GetDPadIsAxisOrButtons())
|
|
{
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::DPadUp))
|
|
std::cout << "DPad Up Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::DPadDown))
|
|
std::cout << "DPad Down Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::DPadLeft))
|
|
std::cout << "DPad Left Pressed" << std::endl;
|
|
|
|
if (jstick::IsButtonDown(jstick::XBoxButton::DPadRight))
|
|
std::cout << "DPad Right Pressed" << std::endl;
|
|
}
|
|
|
|
|
|
std::this_thread::sleep_for(10ms);
|
|
}
|
|
|
|
return 0;
|
|
}
|