Showing the changes to examples/example/scripts/controllerScriptingExamples.js (1 of 1 file). Show all
Unified · Split
| @@ -9,86 +9,88 @@ · 8 unmodified lines | ||
| 9 | 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| 10 | 10 | // |
| 11 | 11 | |
| 12 | +// Assumes you only have the default keyboard connected | |
| 13 | + | |
| 12 | 14 | // Resets every device to its default key bindings: |
| 13 | −Controller.resetAllDeviceBindings() | |
| 15 | +Controller.resetAllDeviceBindings(); | |
| 14 | 16 | |
| 15 | 17 | // Query all actions |
| 16 | −print("All Actions: \n" + Controller.getAllActions()) | |
| 18 | +print("All Actions: \n" + Controller.getAllActions()); | |
| 17 | 19 | |
| 18 | 20 | // Each action stores: |
| 19 | 21 | // action: int representation of enum |
| 20 | −print("Action 5 int: \n" + Controller.getAllActions()[5].action) | |
| 22 | +print("Action 5 int: \n" + Controller.getAllActions()[5].action); | |
| 21 | 23 | |
| 22 | 24 | // actionName: string representation of enum |
| 23 | −print("Action 5 name: \n" + Controller.getAllActions()[5].actionName) | |
| 25 | +print("Action 5 name: \n" + Controller.getAllActions()[5].actionName); | |
| 24 | 26 | |
| 25 | 27 | // inputChannels: list of all inputchannels that control that action |
| 26 | −print("Action 5 input channels: \n" + Controller.getAllActions()[5].inputChannels + "\n") | |
| 28 | +print("Action 5 input channels: \n" + Controller.getAllActions()[5].inputChannels + "\n"); | |
| 27 | 29 | |
| 28 | 30 | |
| 29 | 31 | // Each input channel stores: |
| 30 | 32 | // action: Action that this InputChannel maps to |
| 31 | −print("Input channel action: \n" + Controller.getAllActions()[5].inputChannels[0].action) | |
| 33 | +print("Input channel action: \n" + Controller.getAllActions()[5].inputChannels[0].action); | |
| 32 | 34 | |
| 33 | 35 | // scale: sensitivity of input |
| 34 | −print("Input channel scale: \n" + Controller.getAllActions()[5].inputChannels[0].scale) | |
| 36 | +print("Input channel scale: \n" + Controller.getAllActions()[5].inputChannels[0].scale); | |
| 35 | 37 | |
| 36 | 38 | // input and modifier: Inputs |
| 37 | −print("Input channel input and modifier: \n" + Controller.getAllActions()[5].inputChannels[0].input + "\n" + Controller.getAllActions()[5].inputChannels[0].modifier + "\n") | |
| 39 | +print("Input channel input and modifier: \n" + Controller.getAllActions()[5].inputChannels[0].input + "\n" + Controller.getAllActions()[5].inputChannels[0].modifier + "\n"); | |
| 38 | 40 | |
| 39 | 41 | |
| 40 | 42 | // Each Input stores: |
| 41 | 43 | // device: device of input |
| 42 | −print("Input device: \n" + Controller.getAllActions()[5].inputChannels[0].input.device) | |
| 44 | +print("Input device: \n" + Controller.getAllActions()[5].inputChannels[0].input.device); | |
| 43 | 45 | |
| 44 | 46 | // channel: channel of input |
| 45 | −print("Input channel: \n" + Controller.getAllActions()[5].inputChannels[0].input.channel) | |
| 47 | +print("Input channel: \n" + Controller.getAllActions()[5].inputChannels[0].input.channel); | |
| 46 | 48 | |
| 47 | 49 | // type: type of input (Unknown, Button, Axis, Joint) |
| 48 | −print("Input type: \n" + Controller.getAllActions()[5].inputChannels[0].input.type) | |
| 50 | +print("Input type: \n" + Controller.getAllActions()[5].inputChannels[0].input.type); | |
| 49 | 51 | |
| 50 | 52 | // id: id of input |
| 51 | −print("Input id: \n" + Controller.getAllActions()[5].inputChannels[0].input.id + "\n") | |
| 53 | +print("Input id: \n" + Controller.getAllActions()[5].inputChannels[0].input.id + "\n"); | |
| 52 | 54 | |
| 53 | 55 | |
| 54 | 56 | // You can get the name of a device from its id |
| 55 | −print("Device 1 name: \n" + Controller.getDeviceName(Controller.getAllActions()[5].inputChannels[0].input.id)) | |
| 57 | +print("Device 1 name: \n" + Controller.getDeviceName(Controller.getAllActions()[5].inputChannels[0].input.id)); | |
| 56 | 58 | |
| 57 | 59 | // You can also get all of a devices input channels |
| 58 | −print("Device 1's input channels: \n" + Controller.getAllInputsForDevice(1) + "\n") | |
| 60 | +print("Device 1's input channels: \n" + Controller.getAllInputsForDevice(1) + "\n"); | |
| 59 | 61 | |
| 60 | 62 | |
| 61 | 63 | // Modifying properties: |
| 62 | 64 | // The following code will switch the "w" and "s" key functionality and adjust their scales |
| 63 | −var s = Controller.getAllActions()[0].inputChannels[0] | |
| 64 | −var w = Controller.getAllActions()[1].inputChannels[0] | |
| 65 | +var s = Controller.getAllActions()[0].inputChannels[0]; | |
| 66 | +var w = Controller.getAllActions()[1].inputChannels[0]; | |
| 65 | 67 | |
| 66 | 68 | // You must remove an input controller before modifying it so the old input controller isn't registered anymore |
| 67 | 69 | // removeInputChannel and addInputChannel return true if successful, false otherwise |
| 68 | −Controller.removeInputChannel(s) | |
| 69 | −Controller.removeInputChannel(w) | |
| 70 | −print(s.scale) | |
| 71 | −s.action = 1 | |
| 72 | −s.scale = .01 | |
| 73 | − | |
| 74 | −w.action = 0 | |
| 75 | −w.scale = 10000 | |
| 76 | −Controller.addInputChannel(s) | |
| 77 | −Controller.addInputChannel(w) | |
| 78 | −print(s.scale) | |
| 70 | +Controller.removeInputChannel(s); | |
| 71 | +Controller.removeInputChannel(w); | |
| 72 | +print(s.scale); | |
| 73 | +s.action = 1; | |
| 74 | +s.scale = .01; | |
| 75 | + | |
| 76 | +w.action = 0; | |
| 77 | +w.scale = 10000; | |
| 78 | +Controller.addInputChannel(s); | |
| 79 | +Controller.addInputChannel(w); | |
| 80 | +print(s.scale); | |
| 79 | 81 | |
| 80 | 82 | // You can get all the available inputs for any device |
| 81 | 83 | // Each AvailableInput has: |
| 82 | 84 | // input: the Input itself |
| 83 | 85 | // inputName: string representing the input |
| 84 | −var availableInputs = Controller.getAvailableInputs(1) | |
| 86 | +var availableInputs = Controller.getAvailableInputs(1); | |
| 85 | 87 | for (i = 0; i < availableInputs.length; i++) { |
| 86 | 88 | print(availableInputs[i].inputName); |
| 87 | 89 | } |
| 88 | 90 | |
| 89 | 91 | // You can modify key bindings by using these avaiable inputs |
| 90 | 92 | // This will replace e (up) with 6 |
| 91 | −var e = Controller.getAllActions()[5].inputChannels[0] | |
| 92 | −Controller.removeInputChannel(e) | |
| 93 | −e.input = availableInputs[6].input | |
| 94 | −Controller.addInputChannel(e) | |
| 93 | +var e = Controller.getAllActions()[5].inputChannels[0]; | |
| 94 | +Controller.removeInputChannel(e); | |
| 95 | +e.input = availableInputs[6].input; | |
| 96 | +Controller.addInputChannel(e); | |