Skip to content

Instantly share code, notes, and snippets.

@zawa-works
Last active December 4, 2020 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zawa-works/06e8183e9b9602e540839d1ed7a4641e to your computer and use it in GitHub Desktop.
Save zawa-works/06e8183e9b9602e540839d1ed7a4641e to your computer and use it in GitHub Desktop.
import org.gamecontrolplus.*;
ControlIO control;
ControlDevice device;
void setup() {
control = ControlIO.getInstance(this);
println("使えるデバイス: " + control.getDevices());
//今回の出力結果: [6B controller, Apple Internal Keyboard / Trackpad, Apple Internal Keyboard / Trackpad, Pro Controller]
device = control.getDevice("6B controller");//使うのは0番目(getDevice(0)でも大丈夫)
checkControlType(device);//ボタンの種類がbutton, slider, hatなのか確認
}
void draw() {
for (int i = 0; i < device.getNumberOfButtons(); i++) {
ControlButton button = device.getButton(i);
if (button.pressed())println(i);//押したボタンの数字を表示
}
for (int i = 0; i < device.getNumberOfSliders(); i++) {
ControlSlider slider = device.getSlider(i);
println(i + ": " + slider.getValue());//-1.0 to 1.0
}
//ControlSlider sliderX = device.getSlider("x");
//ControlSlider sliderY = device.getSlider("y");
//print("x: " + (int)sliderX.getValue());
//print(", ");
//println("y: " + (int)sliderY.getValue());
}
void checkControlType(ControlDevice d) {
for (ControlInput input : d.getInputs()) {
if (input instanceof ControlButton)println("button:" + input.getName());
if (input instanceof ControlSlider)println("slider:" + input.getName());
if (input instanceof ControlHat)println("hat: " + input.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment