Message Boards Message Boards

Game controller button to trigger action

Posted 2 years ago

This should not be that difficult, but I'm not seeing the solution. I have a game controller, and in a notebook on my desktop some WL code. The controller sends a "button push" signal to the code just fine, captured by the code in the notebook with a line like this:

Dynamic[ControllerState[2, "B4"]]

However, I would like this to dynamically trigger a function in the code, similar to the way an event handler would work. To simplify things, let's just have it trigger Beep[] when the button is pushed. I could set a timer to repeatedly check the value of the ControllerState, but that can't be the best way to do it. The code is not part of a Manipulate or 3Dgraphics, but rather part of a custom interface.

Can anyone please point me in the right direction?

Thanks in advance.

POSTED BY: Mark Greenberg
2 Replies
Posted 2 years ago

Okay, I feel foolish having asked this question. Dynamic can be confusing, and I have not used external interaction devices like game controllers before. The answer to my question dawned on me after watching several videos on Dynamic and experimenting with various syntaxes. I just need to wrap the function call in Dynamic too. : \

Dynamic[
 If[ControllerState[2, "B4"], Beep[]]
]

Since there is no option to delete this embarrassing post, I hope that it may help someone else who has a similar foggy moment.

POSTED BY: Mark Greenberg

I probably would’ve made the same mistake, Mark. :) Glad you found the solution.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract