diff options
author | endolf <[email protected]> | 2003-07-31 19:34:46 +0000 |
---|---|---|
committer | endolf <[email protected]> | 2003-07-31 19:34:46 +0000 |
commit | b2f4c7ccd86474da65136f8fdf2cfd34d1e94841 (patch) | |
tree | b0ef45439e7f1f5955039bef8654e12e2094ee91 /plugins/linux/src/java | |
parent | 878c5df2d77ce39aac091ede505a3dd94d897dd7 (diff) |
Initial commit of Linux plugin
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/trunk@23 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'plugins/linux/src/java')
7 files changed, 2822 insertions, 0 deletions
diff --git a/plugins/linux/src/java/net/java/games/input/LinuxAxis.java b/plugins/linux/src/java/net/java/games/input/LinuxAxis.java new file mode 100644 index 0000000..28cb9d9 --- /dev/null +++ b/plugins/linux/src/java/net/java/games/input/LinuxAxis.java @@ -0,0 +1,192 @@ +/** + * Copyright (C) 2003 Jeremy Booth ([email protected]) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + */ + +package net.java.games.input; + +import net.java.games.input.AbstractAxis; +import net.java.games.input.LinuxDevice; + +/** Represents an Axis absolute or relative + * + * @author Jeremy Booth ([email protected]) + */ +public class LinuxAxis extends AbstractAxis { + + /** The controller this axis is part of */ + private LinuxDevice controller; + /** The native ID of this axis */ + private int axisID; + /** The null zone, defaulted to 0 */ + private float nullZone = 0.0f; + /** Is this axis analog */ + private boolean isAnalog = true; + /** Are the values returned by getPollData normalised */ + private boolean isNormalized = false; + /** Is this a relative axis */ + private boolean isRelative = false; + /** Should we normalise the value before returning it in getPollData */ + private boolean needsNormalising = false; + /** The minimum possible axis value (not always used) */ + private float minAxisValue; + /** The maximum possibe axis value (not always used */ + private float maxAxisValue; + /** The current value of the axis */ + private float value = 0.0f; + + /** + * Creates a new instance of LinuxAxis + * @param controller The parent Controller + * @param axisID The native ID of this axis + * @param name The name of this axis + * @param id The Axis.Identifier of this axis + * @param deadzone The deadzone (null zone) of this axis + * @param isAnalog Is this axis analog + * @param isNormalized Is this axis normalised + * @param isRelative Is this axis relative + */ + public LinuxAxis(LinuxDevice controller, int axisID, String name, Identifier id, float deadzone, boolean isAnalog, boolean isNormalized, boolean isRelative) { + super(name, id); + this.controller = controller; + this.axisID = axisID; + this.nullZone = deadzone; + this.isAnalog = isAnalog; + this.isNormalized = isNormalized; + this.isRelative = isRelative; + + } + + /** Creates a new instance of LinuxAxis, it will auto normalise the data based on + * the minimum and maximum values provided + * @param controller The parent Controller + * @param axisID The native ID of this axis + * @param name The name of this axis + * @param id The Axis.Identifier of this axis + * @param deadzone The deadzone (null zone) of this axis + * @param isAnalog Is this axis analog + * @param isRelative Is this axis relative + * @param minAxisValue Minimum value that the native library will return for this axis + * @param maxAxisValue Maximum value that the native library will return for this axis + */ + public LinuxAxis(LinuxDevice controller, int axisID, String name, Identifier id, float deadzone, boolean isAnalog, boolean isRelative, float minAxisValue, float maxAxisValue) { + super(name, id); + + this.controller = controller; + this.axisID = axisID; + this.nullZone = deadzone; + this.isAnalog = isAnalog; + this.isNormalized = false; + this.isRelative = isRelative; + this.needsNormalising = true; + this.minAxisValue = minAxisValue; + this.maxAxisValue = maxAxisValue; + + } + + /** Returns <code>true</code> if data returned from <code>poll</code> + * is relative to the last call, or <code>false</code> if data + * is absolute. + * @return Returns <code>true</code> if data returned from <code>poll</code> + * is relative to the last call, or <code>false</code> if data + * is absolute. + */ + public boolean isRelative() { + return isRelative; + } + + /** Returns the suggested dead zone for this axis. Dead zone is the + * amount polled data can vary before considered a significant change + * in value. An application can safely ignore changes less than this + * value in the positive or negative direction. + * @return 0.0f by default, can be overridden + */ + public float getDeadZone() { + return nullZone; + } + + /** Returns whether or not the axis is analog, or false if it is digital. + * @return false by default, can be overridden + */ + public boolean isAnalog() { + return isAnalog; + } + + /** Returns the data from the last time the control has been polled. + * If this axis is a button, the value returned will be either 0.0f or 1.0f. + * If this axis is normalized, the value returned will be between -1.0f and + * 1.0f. + * @return 0.0f by default, can be overridden + */ + public float getPollData() { + if(isPolling()) { + updateValue(); + } + return value; + } + + /** Update this axis data from the latest native poll value + */ + private void updateValue() { + if(isAnalog) { + float tempVal; + + if(isRelative) { + tempVal = (float)controller.getRelAxisValue(axisID); + } else { + tempVal = (float)controller.getAbsAxisValue(axisID); + } + if(needsNormalising) { + if(isRelative) { + if(tempVal>1) { + tempVal = 1; + } else if(tempVal<-1) { + tempVal = -1; + } + value = tempVal; + } else { + //float center = (minAxisValue + maxAxisValue) / 2; + //value = (tempVal - center) / center; + float center = ((maxAxisValue - minAxisValue)/2); + value = (((tempVal - minAxisValue) - center) / center); + //System.out.println("tempVal: " + tempVal + " minAxisValue: " + minAxisValue + " maxAxisValue: " + maxAxisValue + " center: " + center + " value: " + value); + //System.out.flush(); + } + } else { + value = tempVal; + } + } else { + value = (float)controller.getButtonValue(axisID); + } + } + + /** Returns whether or not data polled from this axis is normalized + * between the values of -1.0f and 1.0f. + * @return true by default, can be overridden + */ + public boolean isNormalized() { + return (isNormalized || needsNormalising); + } + +} diff --git a/plugins/linux/src/java/net/java/games/input/LinuxDevice.java b/plugins/linux/src/java/net/java/games/input/LinuxDevice.java new file mode 100644 index 0000000..9ca6016 --- /dev/null +++ b/plugins/linux/src/java/net/java/games/input/LinuxDevice.java @@ -0,0 +1,956 @@ +/** + * Copyright (C) 2003 Jeremy Booth ([email protected]) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + */ +package net.java.games.input; + +import net.java.games.input.AbstractController; +import net.java.games.input.Axis; +import net.java.games.input.Controller; +import java.util.ArrayList; +import java.util.Iterator; + +/** + * Represents a device that is not a keyboard or mouse. + * @author Jeremy Booth ([email protected]) + */ +public class LinuxDevice extends AbstractController { + + /** The name of the device + */ + private String name; + /** The native ID of the device + */ + private int nativeID; + /** The port type the device is attached to. + */ + private PortType portType; + /** List of buttons the device has + */ + private LinuxAxis[] buttons; + /** List of relative axes the device has + */ + private LinuxAxis[] relAxes; + /** List of absolute axes the device has + */ + private LinuxAxis[] absAxes; + /** List of coolie hats the device has + */ + private LinuxHat[] hats; + /** The id's of the coolie hat axes + */ + private int hatAxisIDs[] = new int[8]; + /** The number of buttons the device has + */ + private int numButtons; + /** The number of relative axes the device has + */ + private int numRelAxes; + /** The number of absolute axes the device has + */ + private int numAbsAxes; + /** The number of coolie hats the device has + */ + private int numHats=0; + /** The native button values. + */ + private int[] buttonData; + /** The native relative axes values + */ + private int[] relAxesData; + /** The native absolute axis values + */ + private int[] absAxesData; + /** A guess at the device type. + */ + private Type typeGuess; + /** An array of the list of axes this device has + */ + private ArrayList axesArray = new ArrayList(); + + /** Creates a new instance of LinuxDevice + * @param nativeID The native ID of this device + * @param name The name of this device + * @param numButtons The number of buttons the devices has + * @param numRelAxes The number of raltive axes this device has + * @param numAbsAxes The number of absolute axes this device has + */ + public LinuxDevice(int nativeID, String name, int numButtons, int numRelAxes, int numAbsAxes) { + super(name); + + children = NO_CONTROLLERS; + rumblers = NO_RUMBLERS; + + this.nativeID = nativeID; + + portType = LinuxNativeTypesMap.getPortType(getNativePortType(nativeID)); + + for(int i=0;i<8;i++) { + hatAxisIDs[i] = -1; + } + + this.numButtons = numButtons; + this.numRelAxes = numRelAxes; + this.numAbsAxes = numAbsAxes; + this.numHats = 0; + + buttonData = new int[numButtons]; + relAxesData = new int[numRelAxes]; + absAxesData = new int[numAbsAxes]; + + createButtons(numButtons); + createRelAxes(numRelAxes); + createAbsAxes(numAbsAxes); + createHats(); + + /*ArrayList tempAxes = new ArrayList(); + for(int i=0;i<numButtons;i++) { + Axis tempAxis = buttons[i]; + if(tempAxis!=null) { + tempAxes.add(tempAxis); + } + } + for(int i=0;i<numRelAxes;i++) { + Axis tempAxis = relAxes[i]; + if(tempAxis!=null) { + tempAxes.add(tempAxis); + } + } + for(int i=0;i<numAbsAxes;i++) { + Axis tempAxis = absAxes[i]; + if(tempAxis!=null) { + tempAxes.add(tempAxis); + } + } + + axes = (Axis[]) tempAxes.toArray(axes);*/ + for(int i=0;i<numAbsAxes;i++) { + if(absAxes[i]!=null) { + axesArray.add(absAxes[i]); + } + } + for(int i=0;i<numRelAxes;i++) { + if(relAxes[i]!=null) { + axesArray.add(relAxes[i]); + } + } + for(int i=0;i<numHats;i++) { + if(hats[i]!=null) { + axesArray.add(hats[i]); + } + } + for(int i=0;i<numButtons;i++) { + if(buttons[i]!=null) { + axesArray.add(buttons[i]); + } + } + axes = (Axis[]) axesArray.toArray(axes); + + guessType(); + } + + /*public Axis[] getAxes(){ + Axis retval[] = new Axis[0]; + retval = (Axis []) axesArray.toArray(retval); + return retval; + }*/ + + /** + * Returns the port type that this device is connected to. + * @return The port type + */ + public PortType getPortType() { + return portType; + } + + /** Create the buttons for the device + * @param numButtons The number of buttons the device has + */ + private void createButtons(int numButtons) { + + int supportedButtons[] = new int[numButtons]; + getSupportedButtons(supportedButtons); + buttons = new LinuxAxis[numButtons]; + for(int i=0;i<numButtons;i++) { + buttons[i] = createButton(i, supportedButtons[i]); + //axesArray.add(buttons[i]); + } + } + + /** Create the relative axes for the device + * @param numRelAxes The number of relative axes the device has + */ + private void createRelAxes(int numRelAxes) { + int supportedRelAxes[] = new int[numRelAxes]; + getSupportedRelAxes(supportedRelAxes); + relAxes = new LinuxAxis[numRelAxes]; + for(int i=0;i<numRelAxes;i++) { + relAxes[i] = createRelAxis(i, supportedRelAxes[i]); + //axesArray.add(relAxes[i]); + } + } + + /** Create the absolute axes for the device + * @param numAbsAxes The number of absolute axes the device has + */ + private void createAbsAxes(int numAbsAxes) { + int supportedAbsAxes[] = new int[numAbsAxes]; + getSupportedAbsAxes(supportedAbsAxes); + absAxes = new LinuxAxis[numAbsAxes]; + for(int i=0;i<numAbsAxes;i++) { + // Nasy code here + // Hats underlinux are 2 axis, combine them + if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT0X) { + hatAxisIDs[0] = i; + } else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT0Y) { + hatAxisIDs[1] = i; + } else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT1X) { + hatAxisIDs[2] = i; + } else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT1Y) { + hatAxisIDs[3] = i; + } else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT2X) { + hatAxisIDs[4] = i; + } else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT2Y) { + hatAxisIDs[5] = i; + } else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT3X) { + hatAxisIDs[6] = i; + } else if(supportedAbsAxes[i] == NativeDefinitions.ABS_HAT3Y) { + hatAxisIDs[7] = i; + } else { + absAxes[i] = createAbsAxis(i, supportedAbsAxes[i]); + //axesArray.add(absAxes[i]); + } + } + + } + + /** Create the coolie hats for the device + */ + private void createHats() { + LinuxHat tempHats[] = new LinuxHat[4]; + for(int i=0;i<4;i++) { + int x = i*2; + int y= x+1; + //Check we have at least one hat axis (can hats have just one axis? + if((hatAxisIDs[x]!=-1) || (hatAxisIDs[y]!=-1)) { + String hatName = "Hat " + i; + tempHats[numHats] = createHat(hatName, hatAxisIDs[x], hatAxisIDs[y]); + numHats++; + } + } + hats = new LinuxHat[numHats]; + for(int i=0;i<numHats;i++) { + hats[i] = tempHats[i]; + //axesArray.add(hats[i]); + } + } + + /*private void guessType() { + int joystickCharacteristic=0; + int gamepadCharacteristic=0; + + int supportedButtons[] = new int[numButtons]; + getSupportedButtons(supportedButtons); + + for(int i=0;i<numButtons;i++) { + switch (supportedButtons[i]) { + case NativeDefinitions.BTN_TRIGGER : + case NativeDefinitions.BTN_THUMB : + case NativeDefinitions.BTN_THUMB2 : + case NativeDefinitions.BTN_TOP : + case NativeDefinitions.BTN_TOP2 : + case NativeDefinitions.BTN_PINKIE : + case NativeDefinitions.BTN_BASE : + case NativeDefinitions.BTN_BASE2 : + case NativeDefinitions.BTN_BASE3 : + case NativeDefinitions.BTN_BASE4 : + case NativeDefinitions.BTN_BASE5 : + case NativeDefinitions.BTN_BASE6 : + case NativeDefinitions.BTN_DEAD : + joystickCharacteristic++; + break; + case NativeDefinitions.BTN_A : + case NativeDefinitions.BTN_B : + case NativeDefinitions.BTN_C : + case NativeDefinitions.BTN_X : + case NativeDefinitions.BTN_Y : + case NativeDefinitions.BTN_Z : + case NativeDefinitions.BTN_TL : + case NativeDefinitions.BTN_TR : + case NativeDefinitions.BTN_TL2 : + case NativeDefinitions.BTN_TR2 : + case NativeDefinitions.BTN_SELECT : + case NativeDefinitions.BTN_MODE : + case NativeDefinitions.BTN_THUMBL : + case NativeDefinitions.BTN_THUMBR : + gamepadCharacteristic++; + break; + default: + // no sweat, it's non of the above, erg + } + } + if(joystickCharacteristic > gamepadCharacteristic) { + typeGuess = Type.STICK; + } else { + typeGuess = Type.GAMEPAD; + } + }*/ + + /** Take a guess at the device type. + */ + private void guessType() { + int joystickCharacteristic=0; + int digitiserCharacteristic=0; + int gamepadCharacteristic=0; + int miscCharacteristic=0; + int mouseCharacteristic=0; + + int supportedButtons[] = new int[numButtons]; + getSupportedButtons(supportedButtons); + + for(int i=0;i<numButtons;i++) { + switch (supportedButtons[i]) { + case NativeDefinitions.BTN_TRIGGER : + case NativeDefinitions.BTN_THUMB : + case NativeDefinitions.BTN_THUMB2 : + case NativeDefinitions.BTN_TOP : + case NativeDefinitions.BTN_TOP2 : + case NativeDefinitions.BTN_PINKIE : + case NativeDefinitions.BTN_BASE : + case NativeDefinitions.BTN_BASE2 : + case NativeDefinitions.BTN_BASE3 : + case NativeDefinitions.BTN_BASE4 : + case NativeDefinitions.BTN_BASE5 : + case NativeDefinitions.BTN_BASE6 : + case NativeDefinitions.BTN_DEAD : + joystickCharacteristic++; + break; + case NativeDefinitions.BTN_A : + case NativeDefinitions.BTN_B : + case NativeDefinitions.BTN_C : + case NativeDefinitions.BTN_X : + case NativeDefinitions.BTN_Y : + case NativeDefinitions.BTN_Z : + case NativeDefinitions.BTN_TL : + case NativeDefinitions.BTN_TR : + case NativeDefinitions.BTN_TL2 : + case NativeDefinitions.BTN_TR2 : + case NativeDefinitions.BTN_SELECT : + case NativeDefinitions.BTN_MODE : + case NativeDefinitions.BTN_THUMBL : + case NativeDefinitions.BTN_THUMBR : + gamepadCharacteristic++; + break; + case NativeDefinitions.BTN_0 : + case NativeDefinitions.BTN_1 : + case NativeDefinitions.BTN_2 : + case NativeDefinitions.BTN_3 : + case NativeDefinitions.BTN_4 : + case NativeDefinitions.BTN_5 : + case NativeDefinitions.BTN_6 : + case NativeDefinitions.BTN_7 : + case NativeDefinitions.BTN_8 : + case NativeDefinitions.BTN_9 : + miscCharacteristic++; + break; + case NativeDefinitions.BTN_LEFT : + case NativeDefinitions.BTN_RIGHT : + case NativeDefinitions.BTN_MIDDLE : + case NativeDefinitions.BTN_SIDE : + case NativeDefinitions.BTN_EXTRA : + case NativeDefinitions.BTN_FORWARD : + case NativeDefinitions.BTN_BACK : + mouseCharacteristic++; + break; + case NativeDefinitions.BTN_TOOL_PEN : + case NativeDefinitions.BTN_TOOL_RUBBER : + case NativeDefinitions.BTN_TOOL_BRUSH : + case NativeDefinitions.BTN_TOOL_PENCIL : + case NativeDefinitions.BTN_TOOL_AIRBRUSH : + case NativeDefinitions.BTN_TOOL_FINGER : + case NativeDefinitions.BTN_TOOL_MOUSE : + case NativeDefinitions.BTN_TOOL_LENS : + case NativeDefinitions.BTN_TOUCH : + case NativeDefinitions.BTN_STYLUS : + case NativeDefinitions.BTN_STYLUS2 : + digitiserCharacteristic++; + break; + default: + // no sweat, it's non of the above, erg + } + } + if((joystickCharacteristic >= digitiserCharacteristic) && + (joystickCharacteristic >= gamepadCharacteristic) && + (joystickCharacteristic >= miscCharacteristic) && + (joystickCharacteristic >= mouseCharacteristic)) { + typeGuess = Type.STICK; + } else if((gamepadCharacteristic >= digitiserCharacteristic) && + (gamepadCharacteristic >= joystickCharacteristic) && + (gamepadCharacteristic >= miscCharacteristic) && + (gamepadCharacteristic >= mouseCharacteristic)) { + typeGuess = Type.GAMEPAD; + } else if((digitiserCharacteristic >= gamepadCharacteristic) && + (digitiserCharacteristic >= joystickCharacteristic) && + (digitiserCharacteristic >= miscCharacteristic) && + (digitiserCharacteristic >= mouseCharacteristic)) { + typeGuess = Type.TRACKPAD; + } else if((miscCharacteristic >= gamepadCharacteristic) && + (miscCharacteristic >= joystickCharacteristic) && + (miscCharacteristic >= miscCharacteristic) && + (miscCharacteristic >= mouseCharacteristic)) { + // I'm not sure what one of these would be, but it has axis other + // wise a LinuxKeyboard would have been constructed, so assume its + // some kind of stick; + typeGuess = Type.STICK; + } else if((mouseCharacteristic >= digitiserCharacteristic) && + (mouseCharacteristic >= joystickCharacteristic) && + (mouseCharacteristic >= miscCharacteristic) && + (mouseCharacteristic >= gamepadCharacteristic)) { + // We shouldn't ever get here, as a mouse should have constructed + // a LinuxMouse object, but you never know + typeGuess = Type.MOUSE; + } + } + + /** Create an button for the device + * @param buttonNumber The button number + * @param nativeButtonType The type of button + * @return The new button + */ + private LinuxAxis createButton(int buttonNumber, int nativeButtonType) { + Axis.Identifier id = LinuxNativeTypesMap.getButtonID(nativeButtonType); + String name = LinuxNativeTypesMap.getButtonName(nativeButtonType); + if(name == null) { + name = "Uknown button"; + id = new ButtonID(name); + } + + return new LinuxAxis(this, buttonNumber, name, id, 0, false, true, false); + } + + /** Create a relative axis for the device + * @param axisNumber The native axis id + * @param nativeType The native type + * @return The new axis + */ + private LinuxAxis createRelAxis(int axisNumber, int nativeType) { + Axis.Identifier id = LinuxNativeTypesMap.getRelAxisID(nativeType); + String name = LinuxNativeTypesMap.getRelAxisName(nativeType); + + // This is done to be like the windows version + return new LinuxAxis(this, axisNumber, name, id, 0, true, true, 0, 0); + + //this is what should be done + // return new LinuxAxis(this, axisNumber, name, id, 0, true, false, true); + } + + /** Create an absolute axis for the device + * @param axisNumber The native axis number + * @param nativeType The native tpye + * @return The new axis + */ + private LinuxAxis createAbsAxis(int axisNumber, int nativeType) { + Axis.Identifier id = LinuxNativeTypesMap.getAbsAxisID(nativeType); + String name = LinuxNativeTypesMap.getAbsAxisName(nativeType); + + // Work around for a kernel level (I think) bug that incorrectly reports + // the third axis as a rudder not a throttle on analog (gameport) 3 axis + // 4 button sticks + if((getName().equals("Analog 3-axis 4-button joystick")) && (portType == Controller.PortType.GAME)) { + if((id == Axis.Identifier.RZ) && (name.equals("Rudder"))) { + id = Axis.Identifier.SLIDER; + name = "Throttle"; + } + } + + return new LinuxAxis(this, axisNumber, name, id, getAbsAxisFuzz(axisNumber), true, false, getAbsAxisMinimum(axisNumber), getAbsAxisMaximum(axisNumber)); + //return new LinuxAxis(this, axisNumber, name, id, getAbsAxisFuzz(axisNumber), true, false, false); + } + + /** Create a hat for the device + * @param name The name of the hat to create + * @param xAxisID The axis that is the hats X axis + * @param yAxisID The axis that is the hats Y axis + * @return The new hat + */ + private LinuxHat createHat(String name, int xAxisID, int yAxisID) { + return new LinuxHat(this, name, xAxisID, yAxisID); + } + + /** Polls axes for data. Returns false if the controller is no longer valid. + * Polling reflects the current state of the device when polled. + * @return false if the controller is no longer valid. + */ + public boolean poll() { + int retval = nativePoll(nativeID, buttonData, relAxesData, absAxesData); + if(retval>=0) return true; + return false; + } + + /** + * Retursn the value of a particular button or key + * @param buttonID The button/key to check + * @return The value fo the button/key + */ + public float getButtonValue(int buttonID) { + if(buttonData[buttonID]>0) return 1.0f; + return 0.0f; + } + + /** + * Returns the value of a particular absolute axis + * @param axisID The axis id + * @return The axis value + */ + public float getAbsAxisValue(int axisID) { + return (float) absAxesData[axisID]; + } + + /** + * Returns the value of the requested relative axis. + * @param axisID The native axis ID. + * @return The value of the axis + */ + public float getRelAxisValue(int axisID) { + return (float) relAxesData[axisID]; + } + + /** + * Gets the axis fuzz, used for nullzone information + * @param axisID The axis to get the fuzz for + * @return The axis fuzz. + */ + public float getAbsAxisFuzz(int axisID) { + return (float) getNativeAbsAxisFuzz(nativeID, axisID); + } + + /** + * Returns the maximum value for the requested axis + * @param axisID The native ID of the axis to check + * @return The maximum value + */ + public float getAbsAxisMaximum(int axisID) { + return (float) getNativeAbsAxisMaximum(nativeID, axisID); + } + + /** + * The minimum value the requested axis can have + * @param axisID The native axis ID + * @return The minimum axis value + */ + public float getAbsAxisMinimum(int axisID) { + return (float) getNativeAbsAxisMinimum(nativeID, axisID); + } + + /** Return the enumeration of supported button types for this device + * @param supportedButtons Array to populate + */ + private void getSupportedButtons(int supportedButtons[]) { + getNativeSupportedButtons(nativeID, supportedButtons); + } + + /** Return the enumeration of supported absolute axis types for this device + * @param suportedAbsAxes The array to populate + */ + private void getSupportedAbsAxes(int suportedAbsAxes[]) { + getNativeSupportedAbsAxes(nativeID, suportedAbsAxes); + } + + /** Return the enumeration of supported relative axis types for this device + * @param supportedRelAxes The array to populate + */ + private void getSupportedRelAxes(int supportedRelAxes[]) { + getNativeSupportedRelAxes(nativeID, supportedRelAxes); + } + + /** Native call to get the supported absolute axes for a device + * @param deviceID The native device number + * @param supportedAbsAxes aray to populate + */ + private native void getNativeSupportedAbsAxes(int deviceID, int supportedAbsAxes[]); + /** Native call to get the supported relative axes for a device + * @param deviceID The native device ID + * @param supportedRelAxes the array to populate + */ + private native void getNativeSupportedRelAxes(int deviceID, int supportedRelAxes[]); + /** Native call to get the supported buttons for a device + * @param deviceID The native device ID + * @param supportedButtons The array to populate + */ + private native void getNativeSupportedButtons(int deviceID, int supportedButtons[]); + /** Call to poll the device at the native library + * @param deviceID The native device ID + * @param buttonData Array to populate with button values + * @param relAxesData Array to populate with relative axes values + * @param absAxesData Array to populate with absolute axes values + * @return the number of events read + */ + private native int nativePoll(int deviceID, int buttonData[], int relAxesData[], int absAxesData[]); + /** Returns the fuzz of an axis fro mthe native lib + * @param deviceID The native device id + * @param axisID The native axis ID + * @return The fuzz + */ + private native int getNativeAbsAxisFuzz(int deviceID, int axisID); + /** Gets the maximum value for an absloute axis fr omthe native library + * @param deviceID The native device ID + * @param axisID The native axis ID + * @return The Max value + */ + private native int getNativeAbsAxisMaximum(int deviceID, int axisID); + /** Gets the minimum value for an absloute axis from the native library + * @param deviceID The native device ID + * @param axisID The native axis number + * @return The min value + */ + private native int getNativeAbsAxisMinimum(int deviceID, int axisID); + /** Gets the port type from the native lib + * @param deviceID The device to get the port type for + * @return The port type + */ + private native int getNativePortType(int deviceID); + + /** + * A device that represents a joystick coolie hat. + * @author Jeremy Booth ([email protected]) + */ + public static class LinuxHat extends AbstractAxis { + + /** The parent controller + */ + private LinuxDevice controller; + + /** The xAxis for this hat + */ + private int xAxisID; + + /** The y axis for this hat + */ + private int yAxisID; + + /** The last polled value of this hat + */ + private float value; + + /** + * Creates a new instance of LinuxHat, coolie hats under linux are reported as + * two independant axis, this class is responsible for combining the axis values + * and returning a value appropriate for a coolie hat. + * @param controller The parent controller + * @param name The name of this hat + * @param xAxisID The X axis native axis ID + * @param yAxisID The Y axis native axis ID + */ + public LinuxHat(LinuxDevice controller, String name, int xAxisID, int yAxisID) { + super(name, Axis.Identifier.POV); + + this.controller = controller; + this.xAxisID = xAxisID; + this.yAxisID = yAxisID; + + //System.err.println("New hat: " + name + " created"); + //System.err.flush(); + } + + /** Returns <code>true</code> if data returned from <code>poll</code> + * is relative to the last call, or <code>false</code> if data + * is absolute. + * @return Returns <code>true</code> if data returned from <code>poll</code> + * is relative to the last call, or <code>false</code> if data + * is absolute. + */ + public boolean isRelative() { + return false; + } + + /** Returns true if this axis is analog + * @return Always retursn true as coolie hats are analog under linux + */ + public boolean isAnalog() { + return false; + } + + /** + * Retursn true if this axis is normalised + * @return Always returns true as linux hats are normalised + */ + public boolean isNormalised() { + return true; + } + + /** + * Returns the current value of this axis + * @return The current axis value + */ + public float getPollData() { + //System.err.println("getPollData called, isPolling: " + isPolling()); + //System.err.flush(); + if(isPolling()) { updateData(); }; + return value; + } + + /** Gets the data fro mthe native level and combines it to the hats value + */ + private void updateData() { + //System.err.println("updateData called"); + //System.err.flush(); + int newXAxisValue = (int)controller.getAbsAxisValue(xAxisID); + int newYAxisValue = (int)controller.getAbsAxisValue(yAxisID); + + //System.err.println("newXAxisValue: " + newXAxisValue + " newYAxisValue: " + newYAxisValue); + + if((newXAxisValue == 0) && (newYAxisValue == 0)) { + value = POV.OFF; + } else if((newXAxisValue == 32767) && (newYAxisValue == 32767)) { + value = POV.UP_RIGHT; + } else if((newXAxisValue == 32767) && (newYAxisValue == 0)) { + value = POV.RIGHT; + } else if((newXAxisValue == 32767) && (newYAxisValue == -32767)) { + value = POV.DOWN_RIGHT; + } else if((newXAxisValue == 0) && (newYAxisValue == -32767)) { + value = POV.DOWN; + } else if((newXAxisValue == -32767) && (newYAxisValue == -32767)) { + value = POV.DOWN_LEFT; + } else if((newXAxisValue == -32767) && (newYAxisValue == 0)) { + value = POV.LEFT; + } else if((newXAxisValue == -32767) && (newYAxisValue == 32767)) { + value = POV.UP_LEFT; + } else if((newXAxisValue == 0) && (newYAxisValue == 32767)) { + value = POV.UP; + } + + //System.err.println("new value: " + value); + //System.err.flush(); + } + + } + + /** Some button ID's specific to linux devices + * @author Jeremy Booth ([email protected]) + */ + public static class ButtonID extends Axis.Identifier { + + /** First device button + */ + public static final ButtonID BTN_0 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_0)); + + /** Second device button + */ + public static final ButtonID BTN_1 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_1)); + + /** Thrid device button + */ + public static final ButtonID BTN_2 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_2)); + + /** Fourth device button + */ + public static final ButtonID BTN_3 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_3)); + + /** Fifth device button + */ + public static final ButtonID BTN_4 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_4)); + + /** Sixth device button + */ + public static final ButtonID BTN_5 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_5)); + + /** Seventh device button + */ + public static final ButtonID BTN_6 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_6)); + + /** Eighth (had to check that spelling on dictionary.com) device button + */ + public static final ButtonID BTN_7 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_7)); + + /** Ninth device button + */ + public static final ButtonID BTN_8 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_8)); + + /** 10th device button + */ + public static final ButtonID BTN_9 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_9)); + + /** Joystick trigger button + */ + public static final ButtonID BTN_TRIGGER = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TRIGGER)); + + /** Joystick thumb button + */ + public static final ButtonID BTN_THUMB = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_THUMB)); + + /** Second joystick thumb button + */ + public static final ButtonID BTN_THUMB2 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_THUMB2)); + + /** Joystick top button + */ + public static final ButtonID BTN_TOP = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOP)); + + /** Second joystick top button + */ + public static final ButtonID BTN_TOP2 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOP2)); + + /** The joystick button you play with with you little finger (Pinkie on *that* side + * of the pond :P) + */ + public static final ButtonID BTN_PINKIE = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_PINKIE)); + + /** Joystick button on the base of the device + */ + public static final ButtonID BTN_BASE = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_BASE)); + + /** Second joystick button on the base of the device + */ + public static final ButtonID BTN_BASE2 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_BASE2)); + + /** Thrid joystick button on the base of the device + */ + public static final ButtonID BTN_BASE3 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_BASE3)); + + /** Fourth joystick button on the base of the device + */ + public static final ButtonID BTN_BASE4 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_BASE4)); + + /** Fifth joystick button on the base of the device + */ + public static final ButtonID BTN_BASE5 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_BASE5)); + + /** Sixth joystick button on the base of the device + */ + public static final ButtonID BTN_BASE6 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_BASE6)); + + /** erm, dunno, but it's in the defines so it might exist. + */ + public static final ButtonID BTN_DEAD = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_DEAD)); + + /** 'A' button on a gamepad + */ + public static final ButtonID BTN_A = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_A)); + + /** 'B' button on a gamepad + */ + public static final ButtonID BTN_B = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_B)); + + /** 'C' button on a gamepad + */ + public static final ButtonID BTN_C = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_C)); + + /** 'X' button on a gamepad + */ + public static final ButtonID BTN_X = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_X)); + + /** 'Y' button on a gamepad + */ + public static final ButtonID BTN_Y = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_Y)); + + /** 'Z' button on a gamepad + */ + public static final ButtonID BTN_Z = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_Z)); + + /** Left thumb button on a gamepad + */ + public static final ButtonID BTN_TL = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TL)); + + /** Right thumb button on a gamepad + */ + public static final ButtonID BTN_TR = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TR)); + + /** Second left thumb button on a gamepad + */ + public static final ButtonID BTN_TL2 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TL2)); + + /** Second right thumb button on a gamepad + */ + public static final ButtonID BTN_TR2 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TR2)); + + /** 'Select' button on a gamepad + */ + public static final ButtonID BTN_SELECT = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_SELECT)); + + /** 'Mode' button on a gamepad + */ + public static final ButtonID BTN_MODE = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_MODE)); + + /** Another left thumb button on a gamepad (how many thumbs do you have??) + */ + public static final ButtonID BTN_THUMBL = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_THUMBL)); + + /** Another right thumb button on a gamepad + */ + public static final ButtonID BTN_THUMBR = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_THUMBR)); + + /** Digitiser pen tool button + */ + public static final ButtonID BTN_TOOL_PEN = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOOL_PEN)); + + /** Digitiser rubber (eraser) tool button + */ + public static final ButtonID BTN_TOOL_RUBBER = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOOL_RUBBER)); + + /** Digitiser brush tool button + */ + public static final ButtonID BTN_TOOL_BRUSH = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOOL_BRUSH)); + + /** Digitiser pencil tool button + */ + public static final ButtonID BTN_TOOL_PENCIL = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOOL_PENCIL)); + + /** Digitiser airbrush tool button + */ + public static final ButtonID BTN_TOOL_AIRBRUSH = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOOL_AIRBRUSH)); + + /** Digitiser finger tool button + */ + public static final ButtonID BTN_TOOL_FINGER = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOOL_FINGER)); + + /** Digitiser mouse tool button + */ + public static final ButtonID BTN_TOOL_MOUSE = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOOL_MOUSE)); + + /** Digitiser lens tool button + */ + public static final ButtonID BTN_TOOL_LENS = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOOL_LENS)); + + /** Digitiser touch button + */ + public static final ButtonID BTN_TOUCH = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_TOUCH)); + + /** Digitiser stylus button + */ + public static final ButtonID BTN_STYLUS = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_STYLUS)); + + /** Second digitiser stylus button + */ + public static final ButtonID BTN_STYLUS2 = new ButtonID(LinuxNativeTypesMap.getButtonName(NativeDefinitions.BTN_STYLUS2)); + + /** Create a new Button.Identidier with the passed name + * @param name The name for the new identifier + */ + private ButtonID(String name) { + super(name); + } + + } + +} diff --git a/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java b/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java new file mode 100644 index 0000000..4e0fbe4 --- /dev/null +++ b/plugins/linux/src/java/net/java/games/input/LinuxEnvironmentPlugin.java @@ -0,0 +1,159 @@ +/** + * Copyright (C) 2003 Jeremy Booth ([email protected]) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + */ +package net.java.games.input; + +import java.util.ArrayList; +import java.util.Iterator; +import net.java.games.input.Controller; +import net.java.games.input.ControllerEnvironment; +import net.java.games.util.plugins.Plugin; + +/** Environment plugin for linux + * @author Jeremy Booth ([email protected]) + */ +public class LinuxEnvironmentPlugin extends ControllerEnvironment implements Plugin { + + static { + System.loadLibrary("jinput"); + } + + /** List of controllers + */ + private Controller[] controllers; + + /** Creates a new instance of LinuxEnvironmentPlugin */ + public LinuxEnvironmentPlugin() { + LinuxNativeTypesMap.init(); + init(); + createControllers(); + } + + /** Returns a list of all controllers available to this environment, + * or an empty array if there are no controllers in this environment. + * @return Returns a list of all controllers available to this environment, + * or an empty array if there are no controllers in this environment. + */ + public Controller[] getControllers() { + return controllers; + } + + /** Create the controllers + */ + private void createControllers() { + int numDevices = getNumberOfDevices(); + + controllers = new Controller[numDevices]; + + for(int i=0;i<numDevices;i++) { + controllers[i] = createDevice(i); + } + } + + /** Create a particular device + * @param deviceNumber The device ID + * @return The new device + */ + private Controller createDevice(int deviceNumber) { + String name = getDeviceName(deviceNumber); + int numAbsAxes = getNumAbsAxes(deviceNumber); + int numRelAxes = getNumRelAxes(deviceNumber); + int numButtons = getNumButtons(deviceNumber); + Controller device = null; + + int mouseCharacteristic = 0; + int keyboardCharacteristic = 0; + int joystickCharacteristic = 0; + + // we are going to try and guess what type of controller it is now + if(name.toLowerCase().indexOf("mouse")>=0) { + mouseCharacteristic++; + } + if(name.toLowerCase().indexOf("keyboard")>=0) { + keyboardCharacteristic++; + } + if(name.toLowerCase().indexOf("joystick")>=0) { + joystickCharacteristic++; + } + + if(numRelAxes>=2) { + mouseCharacteristic++; + } else { + mouseCharacteristic--; + } + if(numAbsAxes>=2) { + joystickCharacteristic++; + } else { + joystickCharacteristic--; + } + if(numButtons>64) { + keyboardCharacteristic++; + } else { + keyboardCharacteristic--; + } + + if((mouseCharacteristic > keyboardCharacteristic) && (mouseCharacteristic > joystickCharacteristic)) { + device = new LinuxMouse(new LinuxDevice(deviceNumber, name, numButtons, numRelAxes, numAbsAxes)); + } else if((keyboardCharacteristic > mouseCharacteristic) && (keyboardCharacteristic > joystickCharacteristic)) { + device = new LinuxKeyboard(deviceNumber, name, numButtons, numRelAxes, numAbsAxes); + } else if((joystickCharacteristic > keyboardCharacteristic) && (joystickCharacteristic > mouseCharacteristic)) { + device = new LinuxDevice(deviceNumber, name, numButtons, numRelAxes, numAbsAxes); + } else { + //Dunno what this is, but try it anyway + device = new LinuxDevice(deviceNumber, name, numButtons, numRelAxes, numAbsAxes); + } + return device; + } + + /** Get the name of a device from the native library + * @param deviceID The device id + * @return The devices name + */ + private native String getDeviceName(int deviceID); + /** Get the number of absolute axes for the requested device + * @param deviceID The device ID + * @return The number of abs axes + */ + private native int getNumAbsAxes(int deviceID); + /** Get the nmber or relative axes from the native library + * @param deviceID The native device ID + * @return The number of raltive axes for the device + */ + private native int getNumRelAxes(int deviceID); + /** Gets the number of buttons for the requested devce from the native library + * @param deviceID The device ID + * @return The number of buttons + */ + private native int getNumButtons(int deviceID); + /** Initialises the native library + * @return <0 if something went wrong + */ + private native int init(); + /** Gets the number of devices the native library found + * @return Th number of devices + */ + private native int getNumberOfDevices(); + +} diff --git a/plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java b/plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java new file mode 100644 index 0000000..f03d81d --- /dev/null +++ b/plugins/linux/src/java/net/java/games/input/LinuxKeyboard.java @@ -0,0 +1,232 @@ +/** + * Copyright (C) 2003 Jeremy Booth ([email protected]) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + */ +package net.java.games.input; + +/** Class that represents a keyboard under linux + * @author Jeremy Booth ([email protected]) + */ +public class LinuxKeyboard extends StandardKeyboard { + + /** Values for the keys + */ + private int keyData[]; + /** Needed for the polling methods + */ + private int dummyRelAxesData[]; + /** Needed for the polling methods + */ + private int dummyAbsAxesData[]; + /** Map of native key numbers from jinput key id key indexes. + */ + private int keyMap[]; + /** List of keys this keyboard supports + */ + private int supportedKeys[]; + /** Number of keys this keyboard has + */ + private int numKeys; + /** Port type that this keyboard is connected to. + */ + private PortType portType; + /** The native device id + */ + private int nativeID; + + /** Creates a new instance of LinuxKeyboard + * @param nativeID Native device id + * @param name Name of this keybaord + * @param numButtons Number of keys + * @param numRelAxes Number of relative axes (you never know) + * @param numAbsAxes Number of absolute axes (you never know) + */ + public LinuxKeyboard(int nativeID, String name, int numButtons, int numRelAxes, int numAbsAxes) { + super(name); + + children = NO_CONTROLLERS; + rumblers = NO_RUMBLERS; + + if((numRelAxes > 0) || (numAbsAxes > 0)) { + children = new Controller[1]; + children[0] = new LinuxDevice(nativeID, name + " axis", 0, numRelAxes, numAbsAxes); + } + + this.nativeID = nativeID; + + portType = LinuxNativeTypesMap.getPortType(getNativePortType(nativeID)); + + dummyRelAxesData = new int[numRelAxes]; + dummyAbsAxesData = new int[numAbsAxes]; + + this.numKeys = numButtons; + keyData = new int[numButtons+1]; + supportedKeys = new int[numButtons+1]; + keyMap = new int[KeyID.LAST.getKeyIndex()]; + + getSupportedButtons(supportedKeys); + supportedKeys[numKeys] = NativeDefinitions.KEY_UNKNOWN; + + setupKeyMap(); + renameKeys(); + } + + /** Returns whether or not the given key has been pressed since the last + * call to poll. This is called from a key's getPollData method. + * @param key The key to check + * @return the value fo the key + */ + protected boolean isKeyPressed(Key key) { + /*if(((Keyboard.KeyID) key.getIdentifier()).getKeyIndex() == StandardKeyboard.KeyID.ESCAPE.getKeyIndex()) { + System.out.println("Asked if key " + key + " was pressed"); + System.out.println("key id " + key.getIdentifier()); + System.out.println("keyIndex " + ((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()); + System.out.println("keyMap for index is " + keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]); + System.out.println("name for supportedKeys index is " + LinuxNativeTypesMap.getButtonName(supportedKeys[keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]])); + System.out.println("id for supportedKeys index is " + LinuxNativeTypesMap.getButtonID(supportedKeys[keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]])); + System.out.flush(); + }*/ + if(keyData[keyMap[((Keyboard.KeyID) key.getIdentifier()).getKeyIndex()]] > 0) { + return true; + } + return false; + } + + /** Polls axes for data. Returns false if the controller is no longer valid. + * Polling reflects the current state of the device when polled. + * @return False if this device is invalid. + */ + public boolean poll() { + int retval = nativePoll(nativeID, keyData, dummyRelAxesData, dummyAbsAxesData); + if(retval>=0) return true; + return false; + } + + /** Goes through every key to initialise the key map + */ + private void setupKeyMap() { + for(int i=0;i<KeyID.LAST.getKeyIndex();i++) { + keyMap[i] = numKeys; + } + for(int i=0;i<numKeys;i++) { + int tempNativeID = supportedKeys[i]; + Keyboard.KeyID tempKeyID = StandardKeyboard.KeyID.VOID; + try { + tempKeyID = (Keyboard.KeyID)LinuxNativeTypesMap.getButtonID(tempNativeID); + } catch (ClassCastException e) { + System.out.println("LinuxNativeTypesMap.getButtonID() returned " + LinuxNativeTypesMap.getButtonID(tempNativeID).getClass().toString()); + } + if(tempKeyID.getKeyIndex() < keyMap.length) { + keyMap[tempKeyID.getKeyIndex()] = i; + //System.out.println("keyMap[" + (tempKeyID.getKeyIndex()) + "] (" + tempKeyID + ") set to index " + i + " (" + LinuxNativeTypesMap.getButtonName(supportedKeys[i]) + ")"); + } else { + //System.out.println("Linux key " + LinuxNativeTypesMap.getButtonName(tempNativeID) + " isn't supported by jinput"); + } + } + } + + /** Renames all the keys based on what information we have about them (number/name) + */ + private void renameKeys() { + Axis tempAxes[] = getAxes(); + // Do this one by hand as it's a special case + //((AbstractAxis)tempAxes[0]).setName("Unknown"); + for(int i=0;i<tempAxes.length;i++) { + Axis tempAxis = tempAxes[i]; + int nativeKeyID = supportedKeys[keyMap[((Keyboard.KeyID) tempAxis.getIdentifier()).getKeyIndex()]]; + //System.out.println("key " + tempAxis + " map: " + nativeKeyID); + if(nativeKeyID != NativeDefinitions.KEY_UNKNOWN) { + String tempName = LinuxNativeTypesMap.getButtonName(nativeKeyID); + ((AbstractAxis)tempAxis).setName(tempName); + + /*System.out.println("axis id is " + (Keyboard.KeyID) tempAxis.getIdentifier()); + System.out.println("keyMap[id] is " + keyMap[((Keyboard.KeyID) tempAxis.getIdentifier()).getKeyIndex()]); + System.out.println("nativeKeyID is: " + nativeKeyID); + System.out.println("Set name of key " + ((Keyboard.KeyID) tempAxis.getIdentifier()).getKeyIndex() + " to " + tempName);*/ + } + } + } + + /** Gets all the supported keys for this device + * @param supportedButtons The array if key types to populate + */ + private void getSupportedButtons(int supportedButtons[]) { + getNativeSupportedButtons(nativeID, supportedButtons); + } + + /** Gets the supported key types for a particular native device + * @param deviceID The device ID + * @param supportedButtons The array to populate with teh supported key ids + */ + private native void getNativeSupportedButtons(int deviceID, int supportedButtons[]); + /** Calls the native library to poll the device + * @param deviceID The device ID + * @param buttonData Aray to populate with button values + * @param relAxesData Array to populate with relative axis values + * @param absAxesData Array to populate with absolute axes values + * @return <0 if soething went wrong + */ + private native int nativePoll(int deviceID, int buttonData[], int relAxesData[], int absAxesData[]); + /** Gets the port type from the native library for a particular keyboard + * @param deviceID The keybaord id + * @return native port ype + */ + private native int getNativePortType(int deviceID); + + /** Linux specific key ID's + * @author Jeremy Booth ([email protected]) + */ + public static class KeyID extends StandardKeyboard.KeyID { + + /** The Page up key id + */ + public static final KeyID PAGEUP = new KeyID(StandardKeyboard.KeyID.LAST.getKeyIndex()+1, "Page up"); + /** Page down key id + */ + public static final KeyID PAGEDOWN = new KeyID(StandardKeyboard.KeyID.LAST.getKeyIndex()+1, "Page down"); + /** The last defined key ID + */ + protected static final KeyID LAST = PAGEDOWN; + + /** The name of this key ID + */ + String name; + + /** Construct a new key ID from the passed arguments + * @param keyid The native ID of the key + * @param name The name fo the key + */ + public KeyID(int keyid, String name) { + super(keyid); + this.name = name; + } + + /** Returns a string representing this key ID + * @return String representing this key id + */ + public String toString() { + return super.toString() + " (" + name + ")"; + } + } +} diff --git a/plugins/linux/src/java/net/java/games/input/LinuxMouse.java b/plugins/linux/src/java/net/java/games/input/LinuxMouse.java new file mode 100644 index 0000000..3336905 --- /dev/null +++ b/plugins/linux/src/java/net/java/games/input/LinuxMouse.java @@ -0,0 +1,168 @@ +/** + * Copyright (C) 2003 Jeremy Booth ([email protected]) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + */ +package net.java.games.input; + +/** Class that represents a mouse under linux. + * + * @author Jeremy Booth ([email protected]) + */ +public class LinuxMouse extends Mouse { + + /** The parent linux device + */ + private LinuxDevice device; + + /** Creates a new instance of LinuxMouse + * @param device The parent device + */ + public LinuxMouse(LinuxDevice device) { + super(device.getName()); + + this.device = device; + Axis[] axes = device.getAxes(); + Axis x = null; + Axis y = null; + Axis wheel = null; + Button left = null; + Button right = null; + Button middle = null; + Button side = null; + Button extra = null; + Button forward = null; + Button back = null; + + // start from the back, that way the first one is it + for(int i = (axes.length -1);i>=0;i--) { + Axis tempAxis = axes[i]; + if(tempAxis.isRelative()) { + if(tempAxis.getIdentifier() == Axis.Identifier.X) { + x = tempAxis; + } else if(tempAxis.getIdentifier() == Axis.Identifier.Y) { + y = tempAxis; + } else if(tempAxis.getIdentifier() == Axis.Identifier.SLIDER) { + wheel = tempAxis; + } + } else if(!(tempAxis.isAnalog())) { + if(tempAxis.getIdentifier() == Mouse.ButtonID.LEFT) { + left = new LinuxMouseButton(tempAxis); + } else if(tempAxis.getIdentifier() == Mouse.ButtonID.RIGHT) { + right = new LinuxMouseButton(tempAxis); + } else if(tempAxis.getIdentifier() == Mouse.ButtonID.MIDDLE) { + middle = new LinuxMouseButton(tempAxis); + } else if(tempAxis.getIdentifier() == Mouse.ButtonID.SIDE) { + side = new LinuxMouseButton(tempAxis); + } else if(tempAxis.getIdentifier() == Mouse.ButtonID.EXTRA) { + extra = new LinuxMouseButton(tempAxis); + } else if(tempAxis.getIdentifier() == Mouse.ButtonID.FORWARD) { + forward = new LinuxMouseButton(tempAxis); + } else if(tempAxis.getIdentifier() == Mouse.ButtonID.BACK) { + back = new LinuxMouseButton(tempAxis); + } + } + } + ball = new LinuxMouseBall(x,y,wheel); + buttons = new LinuxMouseButtons(left, right, middle, side, extra, forward, back); + + } + + /** Polls axes for data. Returns false if the controller is no longer valid. + * Polling reflects the current state of the device when polled. + * @return Returns false if the controller is no longer valid. + */ + public boolean poll() { + return device.poll(); + } + + /** Mouse ball under linux + */ + private class LinuxMouseBall extends Ball { + /** Constructs the new mouse ball + * @param x The x axis + * @param y The y axis + * @param wheel The mouse wheel axis + */ + public LinuxMouseBall(Axis x, Axis y, Axis wheel) { + super(LinuxMouse.this.getName() + " ball"); + this.x = x; + this.y = y; + this.wheel = wheel; + } + } + + /** Mouse buttons under linux + */ + private class LinuxMouseButtons extends Buttons { + /** Creates the new mouse's buttons + * @param left Left mouse button + * @param right Right mouse button + * @param middle Middle mouse button + * @param side Side mouse button + * @param extra Extra mouse button + * @param forward Forward mouse button + * @param back Back mouse button + */ + public LinuxMouseButtons(Button left, Button right, Button middle, Button side, Button extra, Button forward, Button back) { + super(LinuxMouse.this.getName() + " buttons"); + this.left = left; + this.right = right; + this.middle = middle; + this.side = side; + this.extra = extra; + this.forward = forward; + this.back = back; + } + } + + /** Linux specific mouse buttons + */ + private class LinuxMouseButton extends Mouse.Button { + /** The real Axis + */ + private Axis realAxis; + + /** Construct a linux mouse button fro mthe given axis + * @param axis The axis that holds the data + */ + public LinuxMouseButton(Axis axis) { + super(axis.getName(), (Mouse.ButtonID)axis.getIdentifier()); + this.realAxis = axis; + } + + /** Returns true f this axis is relative + * @return Always returns false for a mouse button + */ + public boolean isRelative() { + return false; + } + + /** Returns the data for this mouse button + * @return Retursn this mouse buttons value + */ + public float getPollData(){ + return realAxis.getPollData(); + } + } +} diff --git a/plugins/linux/src/java/net/java/games/input/LinuxNativeTypesMap.java b/plugins/linux/src/java/net/java/games/input/LinuxNativeTypesMap.java new file mode 100644 index 0000000..698c18f --- /dev/null +++ b/plugins/linux/src/java/net/java/games/input/LinuxNativeTypesMap.java @@ -0,0 +1,792 @@ +/** + * Copyright (C) 2003 Jeremy Booth ([email protected]) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + */ +package net.java.games.input; + +/** + * Mapping utility class between native type ints and string names or + * Key.Identifiers + * @author Jeremy Booth ([email protected]) + */ +public class LinuxNativeTypesMap { + + /** Instance of they key map + */ + private static LinuxNativeTypesMap INSTANCE = new LinuxNativeTypesMap(); + + /** Indexed array of key names + */ + private String keyNames[]; + /** Inexed array of relative axes names + */ + private String relAxesNames[]; + /** Indexed array of absolute axis names + */ + private String absAxesNames[]; + /** Indexed array of relative axis ID's + */ + private Axis.Identifier relAxesIDs[]; + /** Indexed array of absoulte axis ID's + */ + private Axis.Identifier absAxesIDs[]; + /** Indexed array of button axis ID's + */ + private Axis.Identifier buttonIDs[]; + + /** create an empty, uninitialsed map + */ + private LinuxNativeTypesMap() { + keyNames = new String[NativeDefinitions.KEY_MAX]; + } + + /** Initialise the map, has to be done like this because the map references staic + * classes, as this would otherwise be done in a static class initialiser the whole + * thing blew up as the static classes this class references refer to this class + * this meant that the other classes could not be initialsed until this one was, + * but this class couldn't be loaded until the others were, all went horibly wrong + * and INSTANCE was null whilst initialising the class, ouch. + */ + public static void init() { + INSTANCE.reInit(); + } + + /** Do the work. + */ + private void reInit() { + keyNames[NativeDefinitions.KEY_ESC] = "Escape"; + keyNames[NativeDefinitions.KEY_1] = "1"; + keyNames[NativeDefinitions.KEY_2] = "2"; + keyNames[NativeDefinitions.KEY_3] = "3"; + keyNames[NativeDefinitions.KEY_4] = "4"; + keyNames[NativeDefinitions.KEY_5] = "5"; + keyNames[NativeDefinitions.KEY_6] = "6"; + keyNames[NativeDefinitions.KEY_7] = "7"; + keyNames[NativeDefinitions.KEY_8] = "8"; + keyNames[NativeDefinitions.KEY_9] = "9"; + keyNames[NativeDefinitions.KEY_0] = "0"; + keyNames[NativeDefinitions.KEY_MINUS] = "-"; + keyNames[NativeDefinitions.KEY_EQUAL] = "="; + keyNames[NativeDefinitions.KEY_BACKSPACE] = "Backspace"; + keyNames[NativeDefinitions.KEY_TAB] = "Tab"; + keyNames[NativeDefinitions.KEY_Q] = "Q"; + keyNames[NativeDefinitions.KEY_W] = "W"; + keyNames[NativeDefinitions.KEY_E] = "E"; + keyNames[NativeDefinitions.KEY_R] = "R"; + keyNames[NativeDefinitions.KEY_T] = "T"; + keyNames[NativeDefinitions.KEY_Y] = "Y"; + keyNames[NativeDefinitions.KEY_U] = "U"; + keyNames[NativeDefinitions.KEY_I] = "I"; + keyNames[NativeDefinitions.KEY_O] = "O"; + keyNames[NativeDefinitions.KEY_P] = "P"; + keyNames[NativeDefinitions.KEY_LEFTBRACE] = "["; + keyNames[NativeDefinitions.KEY_RIGHTBRACE] = "]"; + keyNames[NativeDefinitions.KEY_ENTER] = "Enter"; + keyNames[NativeDefinitions.KEY_LEFTCTRL] = "LH Control"; + keyNames[NativeDefinitions.KEY_A] = "A"; + keyNames[NativeDefinitions.KEY_S] = "S"; + keyNames[NativeDefinitions.KEY_D] = "D"; + keyNames[NativeDefinitions.KEY_F] = "F"; + keyNames[NativeDefinitions.KEY_G] = "G"; + keyNames[NativeDefinitions.KEY_H] = "H"; + keyNames[NativeDefinitions.KEY_J] = "J"; + keyNames[NativeDefinitions.KEY_K] = "K"; + keyNames[NativeDefinitions.KEY_L] = "L"; + keyNames[NativeDefinitions.KEY_SEMICOLON] = ";"; + keyNames[NativeDefinitions.KEY_APOSTROPHE] = "'"; + keyNames[NativeDefinitions.KEY_GRAVE] = "`"; + keyNames[NativeDefinitions.KEY_LEFTSHIFT] = "LH Shift"; + keyNames[NativeDefinitions.KEY_BACKSLASH] = "\\"; + keyNames[NativeDefinitions.KEY_Z] = "Z"; + keyNames[NativeDefinitions.KEY_X] = "X"; + keyNames[NativeDefinitions.KEY_C] = "C"; + keyNames[NativeDefinitions.KEY_V] = "V"; + keyNames[NativeDefinitions.KEY_B] = "B"; + keyNames[NativeDefinitions.KEY_N] = "N"; + keyNames[NativeDefinitions.KEY_M] = "M"; + keyNames[NativeDefinitions.KEY_COMMA] = ","; + keyNames[NativeDefinitions.KEY_DOT] = "."; + keyNames[NativeDefinitions.KEY_SLASH] = "/"; + keyNames[NativeDefinitions.KEY_RIGHTSHIFT] = "RH Shift"; + keyNames[NativeDefinitions.KEY_KPASTERISK] = "*"; + keyNames[NativeDefinitions.KEY_LEFTALT] = "LH Alt"; + keyNames[NativeDefinitions.KEY_SPACE] = "Space"; + keyNames[NativeDefinitions.KEY_CAPSLOCK] = "CapsLock"; + keyNames[NativeDefinitions.KEY_F1] = "F1"; + keyNames[NativeDefinitions.KEY_F2] = "F2"; + keyNames[NativeDefinitions.KEY_F3] = "F3"; + keyNames[NativeDefinitions.KEY_F4] = "F4"; + keyNames[NativeDefinitions.KEY_F5] = "F5"; + keyNames[NativeDefinitions.KEY_F6] = "F6"; + keyNames[NativeDefinitions.KEY_F7] = "F7"; + keyNames[NativeDefinitions.KEY_F8] = "F8"; + keyNames[NativeDefinitions.KEY_F9] = "F9"; + keyNames[NativeDefinitions.KEY_F10] = "F10"; + keyNames[NativeDefinitions.KEY_NUMLOCK] = "NumLock"; + keyNames[NativeDefinitions.KEY_SCROLLLOCK] = "ScrollLock"; + keyNames[NativeDefinitions.KEY_KP7] = "KeyPad 7"; + keyNames[NativeDefinitions.KEY_KP8] = "KeyPad 8"; + keyNames[NativeDefinitions.KEY_KP9] = "Keypad 9"; + keyNames[NativeDefinitions.KEY_KPMINUS] = "KeyPad Minus"; + keyNames[NativeDefinitions.KEY_KP4] = "KeyPad 4"; + keyNames[NativeDefinitions.KEY_KP5] = "KeyPad 5"; + keyNames[NativeDefinitions.KEY_KP6] = "KeyPad 6"; + keyNames[NativeDefinitions.KEY_KPPLUS] = "KeyPad Plus"; + keyNames[NativeDefinitions.KEY_KP1] = "KeyPad 1"; + keyNames[NativeDefinitions.KEY_KP2] = "KeyPad 2"; + keyNames[NativeDefinitions.KEY_KP3] = "KeyPad 3"; + keyNames[NativeDefinitions.KEY_KP0] = "KeyPad 0"; + keyNames[NativeDefinitions.KEY_KPDOT] = "KeyPad decimal point"; + keyNames[NativeDefinitions.KEY_103RD] = "Huh?"; + keyNames[NativeDefinitions.KEY_F13] = "F13"; + keyNames[NativeDefinitions.KEY_102ND] = "Beats me..."; + keyNames[NativeDefinitions.KEY_F11] = "F11"; + keyNames[NativeDefinitions.KEY_F12] = "F12"; + keyNames[NativeDefinitions.KEY_F14] = "F14"; + keyNames[NativeDefinitions.KEY_F15] = "F15"; + keyNames[NativeDefinitions.KEY_F16] = "F16"; + keyNames[NativeDefinitions.KEY_F17] = "F17"; + keyNames[NativeDefinitions.KEY_F18] = "F18"; + keyNames[NativeDefinitions.KEY_F19] = "F19"; + keyNames[NativeDefinitions.KEY_F20] = "F20"; + keyNames[NativeDefinitions.KEY_KPENTER] = "Keypad Enter"; + keyNames[NativeDefinitions.KEY_RIGHTCTRL] = "RH Control"; + keyNames[NativeDefinitions.KEY_KPSLASH] = "KeyPad Forward Slash"; + keyNames[NativeDefinitions.KEY_SYSRQ] = "System Request"; + keyNames[NativeDefinitions.KEY_RIGHTALT] = "RH Alternate"; + keyNames[NativeDefinitions.KEY_LINEFEED] = "Line Feed"; + keyNames[NativeDefinitions.KEY_HOME] = "Home"; + keyNames[NativeDefinitions.KEY_UP] = "Up"; + keyNames[NativeDefinitions.KEY_PAGEUP] = "Page Up"; + keyNames[NativeDefinitions.KEY_LEFT] = "Left"; + keyNames[NativeDefinitions.KEY_RIGHT] = "Right"; + keyNames[NativeDefinitions.KEY_END] = "End"; + keyNames[NativeDefinitions.KEY_DOWN] = "Down"; + keyNames[NativeDefinitions.KEY_PAGEDOWN] = "Page Down"; + keyNames[NativeDefinitions.KEY_INSERT] = "Insert"; + keyNames[NativeDefinitions.KEY_DELETE] = "Delete"; + keyNames[NativeDefinitions.KEY_MACRO] = "Macro"; + keyNames[NativeDefinitions.KEY_MUTE] = "Mute"; + keyNames[NativeDefinitions.KEY_VOLUMEDOWN] = "Volume Down"; + keyNames[NativeDefinitions.KEY_VOLUMEUP] = "Volume Up"; + keyNames[NativeDefinitions.KEY_POWER] = "Power"; + keyNames[NativeDefinitions.KEY_KPEQUAL] = "KeyPad Equal"; + keyNames[NativeDefinitions.KEY_KPPLUSMINUS] = "KeyPad +/-"; + keyNames[NativeDefinitions.KEY_PAUSE] = "Pause"; + keyNames[NativeDefinitions.KEY_F21] = "F21"; + keyNames[NativeDefinitions.KEY_F22] = "F22"; + keyNames[NativeDefinitions.KEY_F23] = "F23"; + keyNames[NativeDefinitions.KEY_F24] = "F24"; + keyNames[NativeDefinitions.KEY_KPCOMMA] = "KeyPad comma"; + keyNames[NativeDefinitions.KEY_LEFTMETA] = "LH Meta"; + keyNames[NativeDefinitions.KEY_RIGHTMETA] = "RH Meta"; + keyNames[NativeDefinitions.KEY_COMPOSE] = "Compose"; + keyNames[NativeDefinitions.KEY_STOP] = "Stop"; + keyNames[NativeDefinitions.KEY_AGAIN] = "Again"; + keyNames[NativeDefinitions.KEY_PROPS] = "Properties"; + keyNames[NativeDefinitions.KEY_UNDO] = "Undo"; + keyNames[NativeDefinitions.KEY_FRONT] = "Front"; + keyNames[NativeDefinitions.KEY_COPY] = "Copy"; + keyNames[NativeDefinitions.KEY_OPEN] = "Open"; + keyNames[NativeDefinitions.KEY_PASTE] = "Paste"; + keyNames[NativeDefinitions.KEY_FIND] = "Find"; + keyNames[NativeDefinitions.KEY_CUT] = "Cut"; + keyNames[NativeDefinitions.KEY_HELP] = "Help"; + keyNames[NativeDefinitions.KEY_MENU] = "Menu"; + keyNames[NativeDefinitions.KEY_CALC] = "Calculator"; + keyNames[NativeDefinitions.KEY_SETUP] = "Setup"; + keyNames[NativeDefinitions.KEY_SLEEP] = "Sleep"; + keyNames[NativeDefinitions.KEY_WAKEUP] = "Wakeup"; + keyNames[NativeDefinitions.KEY_FILE] = "File"; + keyNames[NativeDefinitions.KEY_SENDFILE] = "Send File"; + keyNames[NativeDefinitions.KEY_DELETEFILE] = "Delete File"; + keyNames[NativeDefinitions.KEY_XFER] = "Transfer"; + keyNames[NativeDefinitions.KEY_PROG1] = "Program 1"; + keyNames[NativeDefinitions.KEY_PROG2] = "Program 2"; + keyNames[NativeDefinitions.KEY_WWW] = "Web Browser"; + keyNames[NativeDefinitions.KEY_MSDOS] = "DOS mode"; + keyNames[NativeDefinitions.KEY_COFFEE] = "Coffee"; + keyNames[NativeDefinitions.KEY_DIRECTION] = "Direction"; + keyNames[NativeDefinitions.KEY_CYCLEWINDOWS] = "Window cycle"; + keyNames[NativeDefinitions.KEY_MAIL] = "Mail"; + keyNames[NativeDefinitions.KEY_BOOKMARKS] = "Book Marks"; + keyNames[NativeDefinitions.KEY_COMPUTER] = "Computer"; + keyNames[NativeDefinitions.KEY_BACK] = "Back"; + keyNames[NativeDefinitions.KEY_FORWARD] = "Forward"; + keyNames[NativeDefinitions.KEY_CLOSECD] = "Close CD"; + keyNames[NativeDefinitions.KEY_EJECTCD] = "Eject CD"; + keyNames[NativeDefinitions.KEY_EJECTCLOSECD] = "Eject / Close CD"; + keyNames[NativeDefinitions.KEY_NEXTSONG] = "Next Song"; + keyNames[NativeDefinitions.KEY_PLAYPAUSE] = "Play and Pause"; + keyNames[NativeDefinitions.KEY_PREVIOUSSONG] = "Previous Song"; + keyNames[NativeDefinitions.KEY_STOPCD] = "Stop CD"; + keyNames[NativeDefinitions.KEY_RECORD] = "Record"; + keyNames[NativeDefinitions.KEY_REWIND] = "Rewind"; + keyNames[NativeDefinitions.KEY_PHONE] = "Phone"; + keyNames[NativeDefinitions.KEY_ISO] = "ISO"; + keyNames[NativeDefinitions.KEY_CONFIG] = "Config"; + keyNames[NativeDefinitions.KEY_HOMEPAGE] = "Home"; + keyNames[NativeDefinitions.KEY_REFRESH] = "Refresh"; + keyNames[NativeDefinitions.KEY_EXIT] = "Exit"; + keyNames[NativeDefinitions.KEY_MOVE] = "Move"; + keyNames[NativeDefinitions.KEY_EDIT] = "Edit"; + keyNames[NativeDefinitions.KEY_SCROLLUP] = "Scroll Up"; + keyNames[NativeDefinitions.KEY_SCROLLDOWN] = "Scroll Down"; + keyNames[NativeDefinitions.KEY_KPLEFTPAREN] = "KeyPad LH parenthesis"; + keyNames[NativeDefinitions.KEY_KPRIGHTPAREN] = "KeyPad RH parenthesis"; + keyNames[NativeDefinitions.KEY_INTL1] = "Intl 1"; + keyNames[NativeDefinitions.KEY_INTL2] = "Intl 2"; + keyNames[NativeDefinitions.KEY_INTL3] = "Intl 3"; + keyNames[NativeDefinitions.KEY_INTL4] = "Intl 4"; + keyNames[NativeDefinitions.KEY_INTL5] = "Intl 5"; + keyNames[NativeDefinitions.KEY_INTL6] = "Intl 6"; + keyNames[NativeDefinitions.KEY_INTL7] = "Intl 7"; + keyNames[NativeDefinitions.KEY_INTL8] = "Intl 8"; + keyNames[NativeDefinitions.KEY_INTL9] = "Intl 9"; + keyNames[NativeDefinitions.KEY_LANG1] = "Language 1"; + keyNames[NativeDefinitions.KEY_LANG2] = "Language 2"; + keyNames[NativeDefinitions.KEY_LANG3] = "Language 3"; + keyNames[NativeDefinitions.KEY_LANG4] = "Language 4"; + keyNames[NativeDefinitions.KEY_LANG5] = "Language 5"; + keyNames[NativeDefinitions.KEY_LANG6] = "Language 6"; + keyNames[NativeDefinitions.KEY_LANG7] = "Language 7"; + keyNames[NativeDefinitions.KEY_LANG8] = "Language 8"; + keyNames[NativeDefinitions.KEY_LANG9] = "Language 9"; + keyNames[NativeDefinitions.KEY_PLAYCD] = "Play CD"; + keyNames[NativeDefinitions.KEY_PAUSECD] = "Pause CD"; + keyNames[NativeDefinitions.KEY_PROG3] = "Program 3"; + keyNames[NativeDefinitions.KEY_PROG4] = "Program 4"; + keyNames[NativeDefinitions.KEY_SUSPEND] = "Suspend"; + keyNames[NativeDefinitions.KEY_CLOSE] = "Close"; + keyNames[NativeDefinitions.KEY_UNKNOWN] = "Specifically unknown"; + keyNames[NativeDefinitions.KEY_BRIGHTNESSDOWN] = "Brightness Down"; + keyNames[NativeDefinitions.KEY_BRIGHTNESSUP] = "Brightness Up"; + keyNames[NativeDefinitions.BTN_0] = "Button 0"; + keyNames[NativeDefinitions.BTN_1] = "Button 1"; + keyNames[NativeDefinitions.BTN_2] = "Button 2"; + keyNames[NativeDefinitions.BTN_3] = "Button 3"; + keyNames[NativeDefinitions.BTN_4] = "Button 4"; + keyNames[NativeDefinitions.BTN_5] = "Button 5"; + keyNames[NativeDefinitions.BTN_6] = "Button 6"; + keyNames[NativeDefinitions.BTN_7] = "Button 7"; + keyNames[NativeDefinitions.BTN_8] = "Button 8"; + keyNames[NativeDefinitions.BTN_9] = "Button 9"; + keyNames[NativeDefinitions.BTN_LEFT] = "Left Button"; + keyNames[NativeDefinitions.BTN_RIGHT] = "Right Button"; + keyNames[NativeDefinitions.BTN_MIDDLE] = "Middle Button"; + keyNames[NativeDefinitions.BTN_SIDE] = "Side Button"; + keyNames[NativeDefinitions.BTN_EXTRA] = "Extra Button"; + keyNames[NativeDefinitions.BTN_FORWARD] = "Forward Button"; + keyNames[NativeDefinitions.BTN_BACK] = "Back Button"; + keyNames[NativeDefinitions.BTN_TRIGGER] = "Trigger Button"; + keyNames[NativeDefinitions.BTN_THUMB] = "Thumb Button"; + keyNames[NativeDefinitions.BTN_THUMB2] = "Second Thumb Button"; + keyNames[NativeDefinitions.BTN_TOP] = "Top Button"; + keyNames[NativeDefinitions.BTN_TOP2] = "Second Top Button"; + keyNames[NativeDefinitions.BTN_PINKIE] = "Pinkie Button"; + keyNames[NativeDefinitions.BTN_BASE] = "Base Button"; + keyNames[NativeDefinitions.BTN_BASE2] = "Second Base Button"; + keyNames[NativeDefinitions.BTN_BASE3] = "Third Base Button"; + keyNames[NativeDefinitions.BTN_BASE4] = "Fourth Base Button"; + keyNames[NativeDefinitions.BTN_BASE5] = "Fifth Base Button"; + keyNames[NativeDefinitions.BTN_BASE6] = "Sixth Base Button"; + keyNames[NativeDefinitions.BTN_DEAD] = "Dead Button"; + keyNames[NativeDefinitions.BTN_A] = "Button A"; + keyNames[NativeDefinitions.BTN_B] = "Button B"; + keyNames[NativeDefinitions.BTN_C] = "Button C"; + keyNames[NativeDefinitions.BTN_X] = "Button X"; + keyNames[NativeDefinitions.BTN_Y] = "Button Y"; + keyNames[NativeDefinitions.BTN_Z] = "Button Z"; + keyNames[NativeDefinitions.BTN_TL] = "Thumb Left Button"; + keyNames[NativeDefinitions.BTN_TR] = "Thumb Right Button "; + keyNames[NativeDefinitions.BTN_TL2] = "Second Thumb Left Button"; + keyNames[NativeDefinitions.BTN_TR2] = "Second Thumb Right Button "; + keyNames[NativeDefinitions.BTN_SELECT] = "Select Button"; + keyNames[NativeDefinitions.BTN_MODE] = "Mode Button"; + keyNames[NativeDefinitions.BTN_THUMBL] = "Another Left Thumb Button "; + keyNames[NativeDefinitions.BTN_THUMBR] = "Another Right Thumb Button "; + keyNames[NativeDefinitions.BTN_TOOL_PEN] = "Digitiser Pen Tool"; + keyNames[NativeDefinitions.BTN_TOOL_RUBBER] = "Digitiser Rubber Tool"; + keyNames[NativeDefinitions.BTN_TOOL_BRUSH] = "Digitiser Brush Tool"; + keyNames[NativeDefinitions.BTN_TOOL_PENCIL] = "Digitiser Pencil Tool"; + keyNames[NativeDefinitions.BTN_TOOL_AIRBRUSH] = "Digitiser Airbrush Tool"; + keyNames[NativeDefinitions.BTN_TOOL_FINGER] = "Digitiser Finger Tool"; + keyNames[NativeDefinitions.BTN_TOOL_MOUSE] = "Digitiser Mouse Tool"; + keyNames[NativeDefinitions.BTN_TOOL_LENS] = "Digitiser Lens Tool"; + keyNames[NativeDefinitions.BTN_TOUCH] = "Digitiser Touch Button "; + keyNames[NativeDefinitions.BTN_STYLUS] = "Digitiser Stylus Button "; + keyNames[NativeDefinitions.BTN_STYLUS2] = "Second Digitiser Stylus Button "; + + buttonIDs = new Axis.Identifier[NativeDefinitions.KEY_MAX]; + buttonIDs[NativeDefinitions.KEY_ESC] = StandardKeyboard.KeyID.ESCAPE; + buttonIDs[NativeDefinitions.KEY_1] = StandardKeyboard.KeyID._1; + buttonIDs[NativeDefinitions.KEY_2] = StandardKeyboard.KeyID._2; + buttonIDs[NativeDefinitions.KEY_3] = StandardKeyboard.KeyID._3; + buttonIDs[NativeDefinitions.KEY_4] = StandardKeyboard.KeyID._4; + buttonIDs[NativeDefinitions.KEY_5] = StandardKeyboard.KeyID._5; + buttonIDs[NativeDefinitions.KEY_6] = StandardKeyboard.KeyID._6; + buttonIDs[NativeDefinitions.KEY_7] = StandardKeyboard.KeyID._7; + buttonIDs[NativeDefinitions.KEY_8] = StandardKeyboard.KeyID._8; + buttonIDs[NativeDefinitions.KEY_9] = StandardKeyboard.KeyID._9; + buttonIDs[NativeDefinitions.KEY_0] = StandardKeyboard.KeyID._0; + buttonIDs[NativeDefinitions.KEY_MINUS] = StandardKeyboard.KeyID.MINUS; + buttonIDs[NativeDefinitions.KEY_EQUAL] = StandardKeyboard.KeyID.EQUALS; + buttonIDs[NativeDefinitions.KEY_BACKSPACE] = StandardKeyboard.KeyID.BACK; + buttonIDs[NativeDefinitions.KEY_TAB] = StandardKeyboard.KeyID.TAB; + buttonIDs[NativeDefinitions.KEY_Q] = StandardKeyboard.KeyID.Q; + buttonIDs[NativeDefinitions.KEY_W] = StandardKeyboard.KeyID.W; + buttonIDs[NativeDefinitions.KEY_E] = StandardKeyboard.KeyID.E; + buttonIDs[NativeDefinitions.KEY_R] = StandardKeyboard.KeyID.R; + buttonIDs[NativeDefinitions.KEY_T] = StandardKeyboard.KeyID.T; + buttonIDs[NativeDefinitions.KEY_Y] = StandardKeyboard.KeyID.Y; + buttonIDs[NativeDefinitions.KEY_U] = StandardKeyboard.KeyID.U; + buttonIDs[NativeDefinitions.KEY_I] = StandardKeyboard.KeyID.I; + buttonIDs[NativeDefinitions.KEY_O] = StandardKeyboard.KeyID.O; + buttonIDs[NativeDefinitions.KEY_P] = StandardKeyboard.KeyID.P; + buttonIDs[NativeDefinitions.KEY_LEFTBRACE] = StandardKeyboard.KeyID.LBRACKET; + buttonIDs[NativeDefinitions.KEY_RIGHTBRACE] = StandardKeyboard.KeyID.RBRACKET; + buttonIDs[NativeDefinitions.KEY_ENTER] = StandardKeyboard.KeyID.RETURN; + buttonIDs[NativeDefinitions.KEY_LEFTCTRL] = StandardKeyboard.KeyID.LCONTROL; + buttonIDs[NativeDefinitions.KEY_A] = StandardKeyboard.KeyID.A; + buttonIDs[NativeDefinitions.KEY_S] = StandardKeyboard.KeyID.S; + buttonIDs[NativeDefinitions.KEY_D] = StandardKeyboard.KeyID.D; + buttonIDs[NativeDefinitions.KEY_F] = StandardKeyboard.KeyID.F; + buttonIDs[NativeDefinitions.KEY_G] = StandardKeyboard.KeyID.G; + buttonIDs[NativeDefinitions.KEY_H] = StandardKeyboard.KeyID.H; + buttonIDs[NativeDefinitions.KEY_J] = StandardKeyboard.KeyID.J; + buttonIDs[NativeDefinitions.KEY_K] = StandardKeyboard.KeyID.K; + buttonIDs[NativeDefinitions.KEY_L] = StandardKeyboard.KeyID.L; + buttonIDs[NativeDefinitions.KEY_SEMICOLON] = StandardKeyboard.KeyID.SEMICOLON; + buttonIDs[NativeDefinitions.KEY_APOSTROPHE] = StandardKeyboard.KeyID.APOSTROPHE; + buttonIDs[NativeDefinitions.KEY_GRAVE] = StandardKeyboard.KeyID.GRAVE; + buttonIDs[NativeDefinitions.KEY_LEFTSHIFT] = StandardKeyboard.KeyID.LSHIFT; + buttonIDs[NativeDefinitions.KEY_BACKSLASH] = StandardKeyboard.KeyID.BACKSLASH; + buttonIDs[NativeDefinitions.KEY_Z] = StandardKeyboard.KeyID.Z; + buttonIDs[NativeDefinitions.KEY_X] = StandardKeyboard.KeyID.X; + buttonIDs[NativeDefinitions.KEY_C] = StandardKeyboard.KeyID.C; + buttonIDs[NativeDefinitions.KEY_V] = StandardKeyboard.KeyID.V; + buttonIDs[NativeDefinitions.KEY_B] = StandardKeyboard.KeyID.B; + buttonIDs[NativeDefinitions.KEY_N] = StandardKeyboard.KeyID.N; + buttonIDs[NativeDefinitions.KEY_M] = StandardKeyboard.KeyID.M; + buttonIDs[NativeDefinitions.KEY_COMMA] = StandardKeyboard.KeyID.COMMA; + buttonIDs[NativeDefinitions.KEY_DOT] = StandardKeyboard.KeyID.PERIOD; + buttonIDs[NativeDefinitions.KEY_SLASH] = StandardKeyboard.KeyID.SLASH; + buttonIDs[NativeDefinitions.KEY_RIGHTSHIFT] = StandardKeyboard.KeyID.RSHIFT; + buttonIDs[NativeDefinitions.KEY_KPASTERISK] = StandardKeyboard.KeyID.MULTIPLY; + buttonIDs[NativeDefinitions.KEY_LEFTALT] = StandardKeyboard.KeyID.LALT; + buttonIDs[NativeDefinitions.KEY_SPACE] = StandardKeyboard.KeyID.SPACE; + buttonIDs[NativeDefinitions.KEY_CAPSLOCK] = StandardKeyboard.KeyID.CAPITAL; + buttonIDs[NativeDefinitions.KEY_F1] = StandardKeyboard.KeyID.F1; + buttonIDs[NativeDefinitions.KEY_F2] = StandardKeyboard.KeyID.F2; + buttonIDs[NativeDefinitions.KEY_F3] = StandardKeyboard.KeyID.F3; + buttonIDs[NativeDefinitions.KEY_F4] = StandardKeyboard.KeyID.F4; + buttonIDs[NativeDefinitions.KEY_F5] = StandardKeyboard.KeyID.F5; + buttonIDs[NativeDefinitions.KEY_F6] = StandardKeyboard.KeyID.F6; + buttonIDs[NativeDefinitions.KEY_F7] = StandardKeyboard.KeyID.F7; + buttonIDs[NativeDefinitions.KEY_F8] = StandardKeyboard.KeyID.F8; + buttonIDs[NativeDefinitions.KEY_F9] = StandardKeyboard.KeyID.F9; + buttonIDs[NativeDefinitions.KEY_F10] = StandardKeyboard.KeyID.F10; + buttonIDs[NativeDefinitions.KEY_NUMLOCK] = StandardKeyboard.KeyID.NUMLOCK; + buttonIDs[NativeDefinitions.KEY_SCROLLLOCK] = StandardKeyboard.KeyID.SCROLL; + buttonIDs[NativeDefinitions.KEY_KP7] = StandardKeyboard.KeyID.NUMPAD7; + buttonIDs[NativeDefinitions.KEY_KP8] = StandardKeyboard.KeyID.NUMPAD8; + buttonIDs[NativeDefinitions.KEY_KP9] = StandardKeyboard.KeyID.NUMPAD9; + buttonIDs[NativeDefinitions.KEY_KPMINUS] = StandardKeyboard.KeyID.SUBTRACT; + buttonIDs[NativeDefinitions.KEY_KP4] = StandardKeyboard.KeyID.NUMPAD4; + buttonIDs[NativeDefinitions.KEY_KP5] = StandardKeyboard.KeyID.NUMPAD5; + buttonIDs[NativeDefinitions.KEY_KP6] = StandardKeyboard.KeyID.NUMPAD6; + buttonIDs[NativeDefinitions.KEY_KPPLUS] = StandardKeyboard.KeyID.ADD; + buttonIDs[NativeDefinitions.KEY_KP1] = StandardKeyboard.KeyID.NUMPAD1; + buttonIDs[NativeDefinitions.KEY_KP2] = StandardKeyboard.KeyID.NUMPAD2; + buttonIDs[NativeDefinitions.KEY_KP3] = StandardKeyboard.KeyID.NUMPAD3; + buttonIDs[NativeDefinitions.KEY_KP0] = StandardKeyboard.KeyID.NUMPAD0; + buttonIDs[NativeDefinitions.KEY_KPDOT] = StandardKeyboard.KeyID.DECIMAL; + buttonIDs[NativeDefinitions.KEY_103RD] = null; + buttonIDs[NativeDefinitions.KEY_F13] = StandardKeyboard.KeyID.F13; + buttonIDs[NativeDefinitions.KEY_102ND] = null; + buttonIDs[NativeDefinitions.KEY_F11] = StandardKeyboard.KeyID.F11; + buttonIDs[NativeDefinitions.KEY_F12] = StandardKeyboard.KeyID.F12; + buttonIDs[NativeDefinitions.KEY_F14] = StandardKeyboard.KeyID.F14; + buttonIDs[NativeDefinitions.KEY_F15] = StandardKeyboard.KeyID.F15; + buttonIDs[NativeDefinitions.KEY_F16] = null; + buttonIDs[NativeDefinitions.KEY_F17] = null; + buttonIDs[NativeDefinitions.KEY_F18] = null; + buttonIDs[NativeDefinitions.KEY_F19] = null; + buttonIDs[NativeDefinitions.KEY_F20] = null; + buttonIDs[NativeDefinitions.KEY_KPENTER] = StandardKeyboard.KeyID.NUMPADENTER; + buttonIDs[NativeDefinitions.KEY_RIGHTCTRL] = StandardKeyboard.KeyID.RCONTROL; + buttonIDs[NativeDefinitions.KEY_KPSLASH] = StandardKeyboard.KeyID.DIVIDE; + buttonIDs[NativeDefinitions.KEY_SYSRQ] = StandardKeyboard.KeyID.SYSRQ; + buttonIDs[NativeDefinitions.KEY_RIGHTALT] = StandardKeyboard.KeyID.RALT; + buttonIDs[NativeDefinitions.KEY_LINEFEED] = null; + buttonIDs[NativeDefinitions.KEY_HOME] = StandardKeyboard.KeyID.HOME; + buttonIDs[NativeDefinitions.KEY_UP] = StandardKeyboard.KeyID.UP; + buttonIDs[NativeDefinitions.KEY_PAGEUP] = LinuxKeyboard.KeyID.PAGEUP; + buttonIDs[NativeDefinitions.KEY_LEFT] = StandardKeyboard.KeyID.LEFT; + buttonIDs[NativeDefinitions.KEY_RIGHT] = StandardKeyboard.KeyID.RIGHT; + buttonIDs[NativeDefinitions.KEY_END] = StandardKeyboard.KeyID.END; + buttonIDs[NativeDefinitions.KEY_DOWN] = StandardKeyboard.KeyID.DOWN; + buttonIDs[NativeDefinitions.KEY_PAGEDOWN] = LinuxKeyboard.KeyID.PAGEDOWN; + buttonIDs[NativeDefinitions.KEY_INSERT] = StandardKeyboard.KeyID.INSERT; + buttonIDs[NativeDefinitions.KEY_DELETE] = StandardKeyboard.KeyID.DELETE; + buttonIDs[NativeDefinitions.KEY_PAUSE] = StandardKeyboard.KeyID.PAUSE; +/* buttonIDs[NativeDefinitions.KEY_MACRO] = "Macro"; + buttonIDs[NativeDefinitions.KEY_MUTE] = "Mute"; + buttonIDs[NativeDefinitions.KEY_VOLUMEDOWN] = "Volume Down"; + buttonIDs[NativeDefinitions.KEY_VOLUMEUP] = "Volume Up"; + buttonIDs[NativeDefinitions.KEY_POWER] = "Power";*/ + buttonIDs[NativeDefinitions.KEY_KPEQUAL] = StandardKeyboard.KeyID.NUMPADEQUAL; + //buttonIDs[NativeDefinitions.KEY_KPPLUSMINUS] = "KeyPad +/-"; +/* buttonIDs[NativeDefinitions.KEY_F21] = "F21"; + buttonIDs[NativeDefinitions.KEY_F22] = "F22"; + buttonIDs[NativeDefinitions.KEY_F23] = "F23"; + buttonIDs[NativeDefinitions.KEY_F24] = "F24"; + buttonIDs[NativeDefinitions.KEY_KPCOMMA] = "KeyPad comma"; + buttonIDs[NativeDefinitions.KEY_LEFTMETA] = "LH Meta"; + buttonIDs[NativeDefinitions.KEY_RIGHTMETA] = "RH Meta"; + buttonIDs[NativeDefinitions.KEY_COMPOSE] = "Compose"; + buttonIDs[NativeDefinitions.KEY_STOP] = "Stop"; + buttonIDs[NativeDefinitions.KEY_AGAIN] = "Again"; + buttonIDs[NativeDefinitions.KEY_PROPS] = "Properties"; + buttonIDs[NativeDefinitions.KEY_UNDO] = "Undo"; + buttonIDs[NativeDefinitions.KEY_FRONT] = "Front"; + buttonIDs[NativeDefinitions.KEY_COPY] = "Copy"; + buttonIDs[NativeDefinitions.KEY_OPEN] = "Open"; + buttonIDs[NativeDefinitions.KEY_PASTE] = "Paste"; + buttonIDs[NativeDefinitions.KEY_FIND] = "Find"; + buttonIDs[NativeDefinitions.KEY_CUT] = "Cut"; + buttonIDs[NativeDefinitions.KEY_HELP] = "Help"; + buttonIDs[NativeDefinitions.KEY_MENU] = "Menu"; + buttonIDs[NativeDefinitions.KEY_CALC] = "Calculator"; + buttonIDs[NativeDefinitions.KEY_SETUP] = "Setup";*/ + buttonIDs[NativeDefinitions.KEY_SLEEP] = StandardKeyboard.KeyID.SLEEP; + /*buttonIDs[NativeDefinitions.KEY_WAKEUP] = "Wakeup"; + buttonIDs[NativeDefinitions.KEY_FILE] = "File"; + buttonIDs[NativeDefinitions.KEY_SENDFILE] = "Send File"; + buttonIDs[NativeDefinitions.KEY_DELETEFILE] = "Delete File"; + buttonIDs[NativeDefinitions.KEY_XFER] = "Transfer"; + buttonIDs[NativeDefinitions.KEY_PROG1] = "Program 1"; + buttonIDs[NativeDefinitions.KEY_PROG2] = "Program 2"; + buttonIDs[NativeDefinitions.KEY_WWW] = "Web Browser"; + buttonIDs[NativeDefinitions.KEY_MSDOS] = "DOS mode"; + buttonIDs[NativeDefinitions.KEY_COFFEE] = "Coffee"; + buttonIDs[NativeDefinitions.KEY_DIRECTION] = "Direction"; + buttonIDs[NativeDefinitions.KEY_CYCLEWINDOWS] = "Window cycle"; + buttonIDs[NativeDefinitions.KEY_MAIL] = "Mail"; + buttonIDs[NativeDefinitions.KEY_BOOKMARKS] = "Book Marks"; + buttonIDs[NativeDefinitions.KEY_COMPUTER] = "Computer"; + buttonIDs[NativeDefinitions.KEY_BACK] = "Back"; + buttonIDs[NativeDefinitions.KEY_FORWARD] = "Forward"; + buttonIDs[NativeDefinitions.KEY_CLOSECD] = "Close CD"; + buttonIDs[NativeDefinitions.KEY_EJECTCD] = "Eject CD"; + buttonIDs[NativeDefinitions.KEY_EJECTCLOSECD] = "Eject / Close CD"; + buttonIDs[NativeDefinitions.KEY_NEXTSONG] = "Next Song"; + buttonIDs[NativeDefinitions.KEY_PLAYPAUSE] = "Play and Pause"; + buttonIDs[NativeDefinitions.KEY_PREVIOUSSONG] = "Previous Song"; + buttonIDs[NativeDefinitions.KEY_STOPCD] = "Stop CD"; + buttonIDs[NativeDefinitions.KEY_RECORD] = "Record"; + buttonIDs[NativeDefinitions.KEY_REWIND] = "Rewind"; + buttonIDs[NativeDefinitions.KEY_PHONE] = "Phone"; + buttonIDs[NativeDefinitions.KEY_ISO] = "ISO"; + buttonIDs[NativeDefinitions.KEY_CONFIG] = "Config"; + buttonIDs[NativeDefinitions.KEY_HOMEPAGE] = "Home"; + buttonIDs[NativeDefinitions.KEY_REFRESH] = "Refresh"; + buttonIDs[NativeDefinitions.KEY_EXIT] = "Exit"; + buttonIDs[NativeDefinitions.KEY_MOVE] = "Move"; + buttonIDs[NativeDefinitions.KEY_EDIT] = "Edit"; + buttonIDs[NativeDefinitions.KEY_SCROLLUP] = "Scroll Up"; + buttonIDs[NativeDefinitions.KEY_SCROLLDOWN] = "Scroll Down"; + buttonIDs[NativeDefinitions.KEY_KPLEFTPAREN] = "KeyPad LH parenthesis"; + buttonIDs[NativeDefinitions.KEY_KPRIGHTPAREN] = "KeyPad RH parenthesis"; + buttonIDs[NativeDefinitions.KEY_INTL1] = "Intl 1"; + buttonIDs[NativeDefinitions.KEY_INTL2] = "Intl 2"; + buttonIDs[NativeDefinitions.KEY_INTL3] = "Intl 3"; + buttonIDs[NativeDefinitions.KEY_INTL4] = "Intl 4"; + buttonIDs[NativeDefinitions.KEY_INTL5] = "Intl 5"; + buttonIDs[NativeDefinitions.KEY_INTL6] = "Intl 6"; + buttonIDs[NativeDefinitions.KEY_INTL7] = "Intl 7"; + buttonIDs[NativeDefinitions.KEY_INTL8] = "Intl 8"; + buttonIDs[NativeDefinitions.KEY_INTL9] = "Intl 9"; + buttonIDs[NativeDefinitions.KEY_LANG1] = "Language 1"; + buttonIDs[NativeDefinitions.KEY_LANG2] = "Language 2"; + buttonIDs[NativeDefinitions.KEY_LANG3] = "Language 3"; + buttonIDs[NativeDefinitions.KEY_LANG4] = "Language 4"; + buttonIDs[NativeDefinitions.KEY_LANG5] = "Language 5"; + buttonIDs[NativeDefinitions.KEY_LANG6] = "Language 6"; + buttonIDs[NativeDefinitions.KEY_LANG7] = "Language 7"; + buttonIDs[NativeDefinitions.KEY_LANG8] = "Language 8"; + buttonIDs[NativeDefinitions.KEY_LANG9] = "Language 9"; + buttonIDs[NativeDefinitions.KEY_PLAYCD] = "Play CD"; + buttonIDs[NativeDefinitions.KEY_PAUSECD] = "Pause CD"; + buttonIDs[NativeDefinitions.KEY_PROG3] = "Program 3"; + buttonIDs[NativeDefinitions.KEY_PROG4] = "Program 4"; + buttonIDs[NativeDefinitions.KEY_SUSPEND] = "Suspend"; + buttonIDs[NativeDefinitions.KEY_CLOSE] = "Close";*/ + buttonIDs[NativeDefinitions.KEY_UNKNOWN] = StandardKeyboard.KeyID.UNLABELED; + /*buttonIDs[NativeDefinitions.KEY_BRIGHTNESSDOWN] = "Brightness Down"; + buttonIDs[NativeDefinitions.KEY_BRIGHTNESSUP] = "Brightness Up";*/ + + //Msic keys + buttonIDs[NativeDefinitions.BTN_0] = LinuxDevice.ButtonID.BTN_0; + buttonIDs[NativeDefinitions.BTN_1] = LinuxDevice.ButtonID.BTN_1; + buttonIDs[NativeDefinitions.BTN_2] = LinuxDevice.ButtonID.BTN_2; + buttonIDs[NativeDefinitions.BTN_3] = LinuxDevice.ButtonID.BTN_3; + buttonIDs[NativeDefinitions.BTN_4] = LinuxDevice.ButtonID.BTN_4; + buttonIDs[NativeDefinitions.BTN_5] = LinuxDevice.ButtonID.BTN_5; + buttonIDs[NativeDefinitions.BTN_6] = LinuxDevice.ButtonID.BTN_6; + buttonIDs[NativeDefinitions.BTN_7] = LinuxDevice.ButtonID.BTN_7; + buttonIDs[NativeDefinitions.BTN_8] = LinuxDevice.ButtonID.BTN_8; + buttonIDs[NativeDefinitions.BTN_9] = LinuxDevice.ButtonID.BTN_9; + + // Mouse + buttonIDs[NativeDefinitions.BTN_LEFT] = Mouse.ButtonID.LEFT; + buttonIDs[NativeDefinitions.BTN_RIGHT] = Mouse.ButtonID.RIGHT; + buttonIDs[NativeDefinitions.BTN_MIDDLE] = Mouse.ButtonID.MIDDLE; + buttonIDs[NativeDefinitions.BTN_SIDE] = Mouse.ButtonID.SIDE; + buttonIDs[NativeDefinitions.BTN_EXTRA] = Mouse.ButtonID.EXTRA; + buttonIDs[NativeDefinitions.BTN_FORWARD] = Mouse.ButtonID.FORWARD; + buttonIDs[NativeDefinitions.BTN_BACK] = Mouse.ButtonID.BACK; + + // Joystick + buttonIDs[NativeDefinitions.BTN_TRIGGER] = LinuxDevice.ButtonID.BTN_TRIGGER; + buttonIDs[NativeDefinitions.BTN_THUMB] = LinuxDevice.ButtonID.BTN_THUMB; + buttonIDs[NativeDefinitions.BTN_THUMB2] = LinuxDevice.ButtonID.BTN_THUMB2; + buttonIDs[NativeDefinitions.BTN_TOP] = LinuxDevice.ButtonID.BTN_TOP; + buttonIDs[NativeDefinitions.BTN_TOP2] = LinuxDevice.ButtonID.BTN_TOP2; + buttonIDs[NativeDefinitions.BTN_PINKIE] = LinuxDevice.ButtonID.BTN_PINKIE; + buttonIDs[NativeDefinitions.BTN_BASE] = LinuxDevice.ButtonID.BTN_BASE; + buttonIDs[NativeDefinitions.BTN_BASE2] = LinuxDevice.ButtonID.BTN_BASE2; + buttonIDs[NativeDefinitions.BTN_BASE3] = LinuxDevice.ButtonID.BTN_BASE3; + buttonIDs[NativeDefinitions.BTN_BASE4] = LinuxDevice.ButtonID.BTN_BASE4; + buttonIDs[NativeDefinitions.BTN_BASE5] = LinuxDevice.ButtonID.BTN_BASE5; + buttonIDs[NativeDefinitions.BTN_BASE6] = LinuxDevice.ButtonID.BTN_BASE6; + buttonIDs[NativeDefinitions.BTN_DEAD] = LinuxDevice.ButtonID.BTN_DEAD; + + // Gamepad + buttonIDs[NativeDefinitions.BTN_A] = LinuxDevice.ButtonID.BTN_A; + buttonIDs[NativeDefinitions.BTN_B] = LinuxDevice.ButtonID.BTN_B; + buttonIDs[NativeDefinitions.BTN_C] = LinuxDevice.ButtonID.BTN_C; + buttonIDs[NativeDefinitions.BTN_X] = LinuxDevice.ButtonID.BTN_X; + buttonIDs[NativeDefinitions.BTN_Y] = LinuxDevice.ButtonID.BTN_Y; + buttonIDs[NativeDefinitions.BTN_Z] = LinuxDevice.ButtonID.BTN_Z; + buttonIDs[NativeDefinitions.BTN_TL] = LinuxDevice.ButtonID.BTN_TL; + buttonIDs[NativeDefinitions.BTN_TR] = LinuxDevice.ButtonID.BTN_TR; + buttonIDs[NativeDefinitions.BTN_TL2] = LinuxDevice.ButtonID.BTN_TL2; + buttonIDs[NativeDefinitions.BTN_TR2] = LinuxDevice.ButtonID.BTN_TR2; + buttonIDs[NativeDefinitions.BTN_SELECT] = LinuxDevice.ButtonID.BTN_SELECT; + buttonIDs[NativeDefinitions.BTN_MODE] = LinuxDevice.ButtonID.BTN_MODE; + buttonIDs[NativeDefinitions.BTN_THUMBL] = LinuxDevice.ButtonID.BTN_THUMBL; + buttonIDs[NativeDefinitions.BTN_THUMBR] = LinuxDevice.ButtonID.BTN_THUMBR; + + // Digitiser + buttonIDs[NativeDefinitions.BTN_TOOL_PEN] = LinuxDevice.ButtonID.BTN_TOOL_PEN; + buttonIDs[NativeDefinitions.BTN_TOOL_RUBBER] = LinuxDevice.ButtonID.BTN_TOOL_RUBBER; + buttonIDs[NativeDefinitions.BTN_TOOL_BRUSH] = LinuxDevice.ButtonID.BTN_TOOL_BRUSH; + buttonIDs[NativeDefinitions.BTN_TOOL_PENCIL] = LinuxDevice.ButtonID.BTN_TOOL_PENCIL; + buttonIDs[NativeDefinitions.BTN_TOOL_AIRBRUSH] = LinuxDevice.ButtonID.BTN_TOOL_AIRBRUSH; + buttonIDs[NativeDefinitions.BTN_TOOL_FINGER] = LinuxDevice.ButtonID.BTN_TOOL_FINGER; + buttonIDs[NativeDefinitions.BTN_TOOL_MOUSE] = LinuxDevice.ButtonID.BTN_TOOL_MOUSE; + buttonIDs[NativeDefinitions.BTN_TOOL_LENS] = LinuxDevice.ButtonID.BTN_TOOL_LENS; + buttonIDs[NativeDefinitions.BTN_TOUCH] = LinuxDevice.ButtonID.BTN_TOUCH; + buttonIDs[NativeDefinitions.BTN_STYLUS] = LinuxDevice.ButtonID.BTN_STYLUS; + buttonIDs[NativeDefinitions.BTN_STYLUS2] = LinuxDevice.ButtonID.BTN_STYLUS2; + + relAxesNames = new String[NativeDefinitions.REL_MAX]; + relAxesNames[NativeDefinitions.REL_X] = "X axis"; + relAxesNames[NativeDefinitions.REL_Y] = "Y axis"; + relAxesNames[NativeDefinitions.REL_Z] = "Z axis"; + relAxesNames[NativeDefinitions.REL_HWHEEL] ="Horizontal wheel"; + relAxesNames[NativeDefinitions.REL_DIAL] = "Dial"; + relAxesNames[NativeDefinitions.REL_WHEEL] = "Vertical wheel"; + relAxesNames[NativeDefinitions.REL_MISC] = "Miscellaneous"; + + relAxesIDs = new Axis.Identifier[NativeDefinitions.REL_MAX]; + relAxesIDs[NativeDefinitions.REL_X] = Axis.Identifier.X; + relAxesIDs[NativeDefinitions.REL_Y] = Axis.Identifier.Y; + relAxesIDs[NativeDefinitions.REL_Z] = Axis.Identifier.Z; + relAxesIDs[NativeDefinitions.REL_WHEEL] = Axis.Identifier.SLIDER; + // There are guesses as I have no idea what they would be used for + relAxesIDs[NativeDefinitions.REL_HWHEEL] = Axis.Identifier.SLIDER; + relAxesIDs[NativeDefinitions.REL_DIAL] = Axis.Identifier.SLIDER; + relAxesIDs[NativeDefinitions.REL_MISC] = Axis.Identifier.SLIDER; + + absAxesNames = new String[NativeDefinitions.ABS_MAX]; + absAxesNames[NativeDefinitions.ABS_X] = "X axis"; + absAxesNames[NativeDefinitions.ABS_Y] = "Y axis"; + absAxesNames[NativeDefinitions.ABS_Z] = "Z axis"; + absAxesNames[NativeDefinitions.ABS_RX] = "X rate axis"; + absAxesNames[NativeDefinitions.ABS_RY] = "Y rate axis"; + absAxesNames[NativeDefinitions.ABS_RZ] = "Z rate axis"; + absAxesNames[NativeDefinitions.ABS_THROTTLE] = "Throttle"; + absAxesNames[NativeDefinitions.ABS_RUDDER] = "Rudder"; + absAxesNames[NativeDefinitions.ABS_WHEEL] = "Wheel"; + absAxesNames[NativeDefinitions.ABS_GAS] = "Accelerator"; + absAxesNames[NativeDefinitions.ABS_BRAKE] = "Brake"; + // Hats are done this way as they are mapped from two axis down to one + absAxesNames[NativeDefinitions.ABS_HAT0X] = "Hat 1"; + absAxesNames[NativeDefinitions.ABS_HAT0Y] = "Hat 1"; + absAxesNames[NativeDefinitions.ABS_HAT1X] = "Hat 2"; + absAxesNames[NativeDefinitions.ABS_HAT1Y] = "Hat 2"; + absAxesNames[NativeDefinitions.ABS_HAT2X] = "Hat 3"; + absAxesNames[NativeDefinitions.ABS_HAT2Y] = "Hat 3"; + absAxesNames[NativeDefinitions.ABS_HAT3X] = "Hat 4"; + absAxesNames[NativeDefinitions.ABS_HAT3Y] = "Hat 4"; + absAxesNames[NativeDefinitions.ABS_PRESSURE] = "Pressure"; + absAxesNames[NativeDefinitions.ABS_DISTANCE] = "Distance"; + absAxesNames[NativeDefinitions.ABS_TILT_X] = "X axis tilt"; + absAxesNames[NativeDefinitions.ABS_TILT_Y] = "Y axis tilt"; + absAxesNames[NativeDefinitions.ABS_MISC] = "Miscellaneous"; + + absAxesIDs = new Axis.Identifier[NativeDefinitions.ABS_MAX]; + absAxesIDs[NativeDefinitions.ABS_X] = Axis.Identifier.X; + absAxesIDs[NativeDefinitions.ABS_Y] = Axis.Identifier.Y; + absAxesIDs[NativeDefinitions.ABS_Z] = Axis.Identifier.Z; + absAxesIDs[NativeDefinitions.ABS_RX] = Axis.Identifier.RX; + absAxesIDs[NativeDefinitions.ABS_RY] = Axis.Identifier.RY; + absAxesIDs[NativeDefinitions.ABS_RZ] = Axis.Identifier.RZ; + absAxesIDs[NativeDefinitions.ABS_THROTTLE] = Axis.Identifier.SLIDER; + absAxesIDs[NativeDefinitions.ABS_RUDDER] = Axis.Identifier.RZ; + absAxesIDs[NativeDefinitions.ABS_WHEEL] = Axis.Identifier.Y; + absAxesIDs[NativeDefinitions.ABS_GAS] = Axis.Identifier.SLIDER; + absAxesIDs[NativeDefinitions.ABS_BRAKE] = Axis.Identifier.SLIDER; + // Hats are done this way as they are mapped from two axis down to one + absAxesIDs[NativeDefinitions.ABS_HAT0X] = Axis.Identifier.POV; + absAxesIDs[NativeDefinitions.ABS_HAT0Y] = Axis.Identifier.POV; + absAxesIDs[NativeDefinitions.ABS_HAT1X] = Axis.Identifier.POV; + absAxesIDs[NativeDefinitions.ABS_HAT1Y] = Axis.Identifier.POV; + absAxesIDs[NativeDefinitions.ABS_HAT2X] = Axis.Identifier.POV; + absAxesIDs[NativeDefinitions.ABS_HAT2Y] = Axis.Identifier.POV; + absAxesIDs[NativeDefinitions.ABS_HAT3X] = Axis.Identifier.POV; + absAxesIDs[NativeDefinitions.ABS_HAT3Y] = Axis.Identifier.POV; + // erm, yeah + absAxesIDs[NativeDefinitions.ABS_PRESSURE] = null; + absAxesIDs[NativeDefinitions.ABS_DISTANCE] = null; + absAxesIDs[NativeDefinitions.ABS_TILT_X] = null; + absAxesIDs[NativeDefinitions.ABS_TILT_Y] = null; + absAxesIDs[NativeDefinitions.ABS_MISC] = null; + + } + + /** Return port type from a native port type int id + * @param nativeid The native port type + * @return The jinput port type + */ + public static Controller.PortType getPortType(int nativeid) { + // Have to do this one this way as there is no BUS_MAX + switch (nativeid) { + case NativeDefinitions.BUS_GAMEPORT : + return Controller.PortType.GAME; + case NativeDefinitions.BUS_I8042 : + return Controller.PortType.I8042; + case NativeDefinitions.BUS_PARPORT : + return Controller.PortType.PARALLEL; + case NativeDefinitions.BUS_RS232 : + return Controller.PortType.SERIAL; + case NativeDefinitions.BUS_USB : + return Controller.PortType.USB; + default: + return Controller.PortType.UNKNOWN; + } + } + + /** Returns the name of a native button + * @param nativeID The native button type id + * @return The button name + */ + public static String getButtonName(int nativeID) { + String retval = INSTANCE.keyNames[nativeID]; + //if(retval == null){ + // retval = "Unknown button id"; + // INSTANCE.keyNames[nativeID] = retval; + //} + return retval; + } + + /** Retursn the name of the native relative axis + * @param nativeID The axis type ID + * @return The axis name + */ + public static String getRelAxisName(int nativeID) { + String retval = INSTANCE.relAxesNames[nativeID]; + if(retval == null) { + retval = "Unknown relative axis id"; + INSTANCE.relAxesNames[nativeID] = retval; + } + return retval; + } + + /** Retursn the name of the native absolute axis + * @param nativeID The native axis type ID + * @return The name of the axis + */ + public static String getAbsAxisName(int nativeID) { + String retval = INSTANCE.absAxesNames[nativeID]; + if(retval == null) { + retval = "Unknown absolute axis id"; + INSTANCE.absAxesNames[nativeID] = retval; + } + return retval; + } + + /** Gets the identifier for a relative axis + * @param nativeID The axis type ID + * @return The jinput id + */ + public static Axis.Identifier getRelAxisID(int nativeID) { + Axis.Identifier retval = INSTANCE.relAxesIDs[nativeID]; + if(retval == null) { + retval = Axis.Identifier.SLIDER_VELOCITY; + INSTANCE.relAxesIDs[nativeID] = retval; + } + return retval; + } + + /** Gets the identifier for a absolute axis + * @param nativeID The native axis type id + * @return The jinput id + */ + public static Axis.Identifier getAbsAxisID(int nativeID) { + Axis.Identifier retval = INSTANCE.absAxesIDs[nativeID]; + if(retval == null) { + retval = Axis.Identifier.SLIDER; + INSTANCE.absAxesIDs[nativeID] = retval; + } + return retval; + } + + /** Gets the identifier for a button + * @param nativeID The native button type id + * @return The jinput id + */ + public static Axis.Identifier getButtonID(int nativeID) { + Axis.Identifier retval = INSTANCE.buttonIDs[nativeID]; + if(retval == null) { + //System.out.println("Creating new KeyID for nativeID " + nativeID); + retval = new LinuxKeyboard.KeyID(nativeID, getButtonName(nativeID)); + INSTANCE.buttonIDs[nativeID] = retval; + } + return retval; + } + +} diff --git a/plugins/linux/src/java/net/java/games/input/NativeDefinitions.java b/plugins/linux/src/java/net/java/games/input/NativeDefinitions.java new file mode 100644 index 0000000..12d3379 --- /dev/null +++ b/plugins/linux/src/java/net/java/games/input/NativeDefinitions.java @@ -0,0 +1,323 @@ +package net.java.games.input; + + +/** + * This file is generated from /usr/include/linux/input.h please do not edit + */ +public class NativeDefinitions { + public static final int KEY_RESERVED = 0; + public static final int KEY_ESC = 1; + public static final int KEY_1 = 2; + public static final int KEY_2 = 3; + public static final int KEY_3 = 4; + public static final int KEY_4 = 5; + public static final int KEY_5 = 6; + public static final int KEY_6 = 7; + public static final int KEY_7 = 8; + public static final int KEY_8 = 9; + public static final int KEY_9 = 10; + public static final int KEY_0 = 11; + public static final int KEY_MINUS = 12; + public static final int KEY_EQUAL = 13; + public static final int KEY_BACKSPACE = 14; + public static final int KEY_TAB = 15; + public static final int KEY_Q = 16; + public static final int KEY_W = 17; + public static final int KEY_E = 18; + public static final int KEY_R = 19; + public static final int KEY_T = 20; + public static final int KEY_Y = 21; + public static final int KEY_U = 22; + public static final int KEY_I = 23; + public static final int KEY_O = 24; + public static final int KEY_P = 25; + public static final int KEY_LEFTBRACE = 26; + public static final int KEY_RIGHTBRACE = 27; + public static final int KEY_ENTER = 28; + public static final int KEY_LEFTCTRL = 29; + public static final int KEY_A = 30; + public static final int KEY_S = 31; + public static final int KEY_D = 32; + public static final int KEY_F = 33; + public static final int KEY_G = 34; + public static final int KEY_H = 35; + public static final int KEY_J = 36; + public static final int KEY_K = 37; + public static final int KEY_L = 38; + public static final int KEY_SEMICOLON = 39; + public static final int KEY_APOSTROPHE = 40; + public static final int KEY_GRAVE = 41; + public static final int KEY_LEFTSHIFT = 42; + public static final int KEY_BACKSLASH = 43; + public static final int KEY_Z = 44; + public static final int KEY_X = 45; + public static final int KEY_C = 46; + public static final int KEY_V = 47; + public static final int KEY_B = 48; + public static final int KEY_N = 49; + public static final int KEY_M = 50; + public static final int KEY_COMMA = 51; + public static final int KEY_DOT = 52; + public static final int KEY_SLASH = 53; + public static final int KEY_RIGHTSHIFT = 54; + public static final int KEY_KPASTERISK = 55; + public static final int KEY_LEFTALT = 56; + public static final int KEY_SPACE = 57; + public static final int KEY_CAPSLOCK = 58; + public static final int KEY_F1 = 59; + public static final int KEY_F2 = 60; + public static final int KEY_F3 = 61; + public static final int KEY_F4 = 62; + public static final int KEY_F5 = 63; + public static final int KEY_F6 = 64; + public static final int KEY_F7 = 65; + public static final int KEY_F8 = 66; + public static final int KEY_F9 = 67; + public static final int KEY_F10 = 68; + public static final int KEY_NUMLOCK = 69; + public static final int KEY_SCROLLLOCK = 70; + public static final int KEY_KP7 = 71; + public static final int KEY_KP8 = 72; + public static final int KEY_KP9 = 73; + public static final int KEY_KPMINUS = 74; + public static final int KEY_KP4 = 75; + public static final int KEY_KP5 = 76; + public static final int KEY_KP6 = 77; + public static final int KEY_KPPLUS = 78; + public static final int KEY_KP1 = 79; + public static final int KEY_KP2 = 80; + public static final int KEY_KP3 = 81; + public static final int KEY_KP0 = 82; + public static final int KEY_KPDOT = 83; + public static final int KEY_103RD = 84; + public static final int KEY_F13 = 85; + public static final int KEY_102ND = 86; + public static final int KEY_F11 = 87; + public static final int KEY_F12 = 88; + public static final int KEY_F14 = 89; + public static final int KEY_F15 = 90; + public static final int KEY_F16 = 91; + public static final int KEY_F17 = 92; + public static final int KEY_F18 = 93; + public static final int KEY_F19 = 94; + public static final int KEY_F20 = 95; + public static final int KEY_KPENTER = 96; + public static final int KEY_RIGHTCTRL = 97; + public static final int KEY_KPSLASH = 98; + public static final int KEY_SYSRQ = 99; + public static final int KEY_RIGHTALT = 100; + public static final int KEY_LINEFEED = 101; + public static final int KEY_HOME = 102; + public static final int KEY_UP = 103; + public static final int KEY_PAGEUP = 104; + public static final int KEY_LEFT = 105; + public static final int KEY_RIGHT = 106; + public static final int KEY_END = 107; + public static final int KEY_DOWN = 108; + public static final int KEY_PAGEDOWN = 109; + public static final int KEY_INSERT = 110; + public static final int KEY_DELETE = 111; + public static final int KEY_MACRO = 112; + public static final int KEY_MUTE = 113; + public static final int KEY_VOLUMEDOWN = 114; + public static final int KEY_VOLUMEUP = 115; + public static final int KEY_POWER = 116; + public static final int KEY_KPEQUAL = 117; + public static final int KEY_KPPLUSMINUS = 118; + public static final int KEY_PAUSE = 119; + public static final int KEY_F21 = 120; + public static final int KEY_F22 = 121; + public static final int KEY_F23 = 122; + public static final int KEY_F24 = 123; + public static final int KEY_KPCOMMA = 124; + public static final int KEY_LEFTMETA = 125; + public static final int KEY_RIGHTMETA = 126; + public static final int KEY_COMPOSE = 127; + public static final int KEY_STOP = 128; + public static final int KEY_AGAIN = 129; + public static final int KEY_PROPS = 130; + public static final int KEY_UNDO = 131; + public static final int KEY_FRONT = 132; + public static final int KEY_COPY = 133; + public static final int KEY_OPEN = 134; + public static final int KEY_PASTE = 135; + public static final int KEY_FIND = 136; + public static final int KEY_CUT = 137; + public static final int KEY_HELP = 138; + public static final int KEY_MENU = 139; + public static final int KEY_CALC = 140; + public static final int KEY_SETUP = 141; + public static final int KEY_SLEEP = 142; + public static final int KEY_WAKEUP = 143; + public static final int KEY_FILE = 144; + public static final int KEY_SENDFILE = 145; + public static final int KEY_DELETEFILE = 146; + public static final int KEY_XFER = 147; + public static final int KEY_PROG1 = 148; + public static final int KEY_PROG2 = 149; + public static final int KEY_WWW = 150; + public static final int KEY_MSDOS = 151; + public static final int KEY_COFFEE = 152; + public static final int KEY_DIRECTION = 153; + public static final int KEY_CYCLEWINDOWS = 154; + public static final int KEY_MAIL = 155; + public static final int KEY_BOOKMARKS = 156; + public static final int KEY_COMPUTER = 157; + public static final int KEY_BACK = 158; + public static final int KEY_FORWARD = 159; + public static final int KEY_CLOSECD = 160; + public static final int KEY_EJECTCD = 161; + public static final int KEY_EJECTCLOSECD = 162; + public static final int KEY_NEXTSONG = 163; + public static final int KEY_PLAYPAUSE = 164; + public static final int KEY_PREVIOUSSONG = 165; + public static final int KEY_STOPCD = 166; + public static final int KEY_RECORD = 167; + public static final int KEY_REWIND = 168; + public static final int KEY_PHONE = 169; + public static final int KEY_ISO = 170; + public static final int KEY_CONFIG = 171; + public static final int KEY_HOMEPAGE = 172; + public static final int KEY_REFRESH = 173; + public static final int KEY_EXIT = 174; + public static final int KEY_MOVE = 175; + public static final int KEY_EDIT = 176; + public static final int KEY_SCROLLUP = 177; + public static final int KEY_SCROLLDOWN = 178; + public static final int KEY_KPLEFTPAREN = 179; + public static final int KEY_KPRIGHTPAREN = 180; + public static final int KEY_INTL1 = 181; + public static final int KEY_INTL2 = 182; + public static final int KEY_INTL3 = 183; + public static final int KEY_INTL4 = 184; + public static final int KEY_INTL5 = 185; + public static final int KEY_INTL6 = 186; + public static final int KEY_INTL7 = 187; + public static final int KEY_INTL8 = 188; + public static final int KEY_INTL9 = 189; + public static final int KEY_LANG1 = 190; + public static final int KEY_LANG2 = 191; + public static final int KEY_LANG3 = 192; + public static final int KEY_LANG4 = 193; + public static final int KEY_LANG5 = 194; + public static final int KEY_LANG6 = 195; + public static final int KEY_LANG7 = 196; + public static final int KEY_LANG8 = 197; + public static final int KEY_LANG9 = 198; + public static final int KEY_PLAYCD = 200; + public static final int KEY_PAUSECD = 201; + public static final int KEY_PROG3 = 202; + public static final int KEY_PROG4 = 203; + public static final int KEY_SUSPEND = 205; + public static final int KEY_CLOSE = 206; + public static final int KEY_UNKNOWN = 220; + public static final int KEY_BRIGHTNESSDOWN = 224; + public static final int KEY_BRIGHTNESSUP = 225; + public static final int BTN_MISC = 0x100; + public static final int BTN_0 = 0x100; + public static final int BTN_1 = 0x101; + public static final int BTN_2 = 0x102; + public static final int BTN_3 = 0x103; + public static final int BTN_4 = 0x104; + public static final int BTN_5 = 0x105; + public static final int BTN_6 = 0x106; + public static final int BTN_7 = 0x107; + public static final int BTN_8 = 0x108; + public static final int BTN_9 = 0x109; + public static final int BTN_MOUSE = 0x110; + public static final int BTN_LEFT = 0x110; + public static final int BTN_RIGHT = 0x111; + public static final int BTN_MIDDLE = 0x112; + public static final int BTN_SIDE = 0x113; + public static final int BTN_EXTRA = 0x114; + public static final int BTN_FORWARD = 0x115; + public static final int BTN_BACK = 0x116; + public static final int BTN_JOYSTICK = 0x120; + public static final int BTN_TRIGGER = 0x120; + public static final int BTN_THUMB = 0x121; + public static final int BTN_THUMB2 = 0x122; + public static final int BTN_TOP = 0x123; + public static final int BTN_TOP2 = 0x124; + public static final int BTN_PINKIE = 0x125; + public static final int BTN_BASE = 0x126; + public static final int BTN_BASE2 = 0x127; + public static final int BTN_BASE3 = 0x128; + public static final int BTN_BASE4 = 0x129; + public static final int BTN_BASE5 = 0x12a; + public static final int BTN_BASE6 = 0x12b; + public static final int BTN_DEAD = 0x12f; + public static final int BTN_GAMEPAD = 0x130; + public static final int BTN_A = 0x130; + public static final int BTN_B = 0x131; + public static final int BTN_C = 0x132; + public static final int BTN_X = 0x133; + public static final int BTN_Y = 0x134; + public static final int BTN_Z = 0x135; + public static final int BTN_TL = 0x136; + public static final int BTN_TR = 0x137; + public static final int BTN_TL2 = 0x138; + public static final int BTN_TR2 = 0x139; + public static final int BTN_SELECT = 0x13a; + public static final int BTN_START = 0x13b; + public static final int BTN_MODE = 0x13c; + public static final int BTN_THUMBL = 0x13d; + public static final int BTN_THUMBR = 0x13e; + public static final int BTN_DIGI = 0x140; + public static final int BTN_TOOL_PEN = 0x140; + public static final int BTN_TOOL_RUBBER = 0x141; + public static final int BTN_TOOL_BRUSH = 0x142; + public static final int BTN_TOOL_PENCIL = 0x143; + public static final int BTN_TOOL_AIRBRUSH = 0x144; + public static final int BTN_TOOL_FINGER = 0x145; + public static final int BTN_TOOL_MOUSE = 0x146; + public static final int BTN_TOOL_LENS = 0x147; + public static final int BTN_TOUCH = 0x14a; + public static final int BTN_STYLUS = 0x14b; + public static final int BTN_STYLUS2 = 0x14c; + public static final int KEY_MAX = 0x1ff; + public static final int REL_X = 0x00; + public static final int REL_Y = 0x01; + public static final int REL_Z = 0x02; + public static final int REL_HWHEEL = 0x06; + public static final int REL_DIAL = 0x07; + public static final int REL_WHEEL = 0x08; + public static final int REL_MISC = 0x09; + public static final int REL_MAX = 0x0f; + public static final int ABS_X = 0x00; + public static final int ABS_Y = 0x01; + public static final int ABS_Z = 0x02; + public static final int ABS_RX = 0x03; + public static final int ABS_RY = 0x04; + public static final int ABS_RZ = 0x05; + public static final int ABS_THROTTLE = 0x06; + public static final int ABS_RUDDER = 0x07; + public static final int ABS_WHEEL = 0x08; + public static final int ABS_GAS = 0x09; + public static final int ABS_BRAKE = 0x0a; + public static final int ABS_HAT0X = 0x10; + public static final int ABS_HAT0Y = 0x11; + public static final int ABS_HAT1X = 0x12; + public static final int ABS_HAT1Y = 0x13; + public static final int ABS_HAT2X = 0x14; + public static final int ABS_HAT2Y = 0x15; + public static final int ABS_HAT3X = 0x16; + public static final int ABS_HAT3Y = 0x17; + public static final int ABS_PRESSURE = 0x18; + public static final int ABS_DISTANCE = 0x19; + public static final int ABS_TILT_X = 0x1a; + public static final int ABS_TILT_Y = 0x1b; + public static final int ABS_MISC = 0x1c; + public static final int ABS_MAX = 0x1f; + public static final int BUS_PCI = 0x01; + public static final int BUS_ISAPNP = 0x02; + public static final int BUS_USB = 0x03; + public static final int BUS_ISA = 0x10; + public static final int BUS_I8042 = 0x11; + public static final int BUS_XTKBD = 0x12; + public static final int BUS_RS232 = 0x13; + public static final int BUS_GAMEPORT = 0x14; + public static final int BUS_PARPORT = 0x15; + public static final int BUS_AMIGA = 0x16; + public static final int BUS_ADB = 0x17; + public static final int BUS_I2C = 0x18; +} |