Hatswitch Arrow Keys

The goal of this example is to demonstrate how to use a joystick hatswitch to trigger multiple keyboard keys when it is pushed. This assumes that the reader is familiar with the basics of creating Building Blocks as shown in the Detailed Tutorial.

This example will generate the four keyboard arrow keys based on the current position of the hatswitch on the CH Products CH Pro Throttle USB. When the hatswitch is pushed to one of the diagonal positions, two arrow keys will be generated simultaneously.

For this example, three types of building blocks are needed: Hatswitch building blocks that respond to the hatswitch, Value Selector building blocks to detect when the hatswitch is pushed in a direction that corresponds to an arrow key, and Single Key building blocks to generate the arrow keys.

The values that the hatswitch generates for each position can be determined by creating a Hatswitch building block, then observing the block's output value as the hatswitch is moved to each position. The hatswitch on the CH Products CH Pro Throttle USB generates the following values:

Hatswitch PositionHatswitch Value
Center0
Right1
Down-Right2
Down3
Down-Left4
Left5
Up-Left6
Up7
Up-Right8

This example will generate the four arrow keys when the hatswitch has the following values:

Keyboard KeyHatswitch Values
Up Arrow6, 7, 8
Down Arrow2, 3, 4
Left Arrow4, 5, 6
Right Arrow1, 2, 8

Each Value Selector block is configured with the hatswitch values for one of the arrow keys. The Value Selector will turn its output ON when the hatswitch produces any one of these values.

For example, the highlighted Value Selector block to the right will turn its output ON when the hatswitch is pushed straight down or diagonally down.


The next step is to create four Single Key building blocks and connect one to each of the Value Selector building blocks.

Each Single Key block is configured to generate the keyboard arrow key that corresponds to the direction that its Value Selector block detects.

With building blocks configured in this manner, ControllerMate will generate keyboard arrow keys in response to the hatswitch on the CH Products CH Pro Throttle USB. An easy way to verify the proper operation of these building blocks is to open the Keyboard Viewer that is included with OS X. The Keyboard Viewer window will show which keys are currently pressed on a physical keyboard, or on ControllerMate's virtual keyboard.