PinballY lets you reassign all of the standard keyboard and joystick command assignments via the Options dialog, so it's straightforward to customize the button settings for your pin cab layout.
But there are certain button commands that PinballY "overloads", meaning that the same button has multiple functions, which depend on the context. For example, the Next and Previous keys are used to navigate through the game wheel UI, and they're also used to navigate through menus. One person on the forums pointed out that his personal sense of what "Next" and "Previous" should mean is reversed between the wheel UI and menus, which makes the way PinballY conflates the two functions feel wrong to him.
Fortunately, Javascript gives us the power to change the meanings of button commands according to context. Let's look at how we can reverse the meanings of the "Next" and "Previous" keys when we're in a menu, and leave them unchanged everywhere else.
To make this work, we'll take advantage of three Javascript features:
The code needed is pretty simple. We set up an event listener for the commandbuttondown event and check the UI mode to see if we're in a menu. If so, we check the command being executed to see if it's a Next or Previous command. If all of these things are true, execute the opposite command (if it's Next, we execute Previous, and if it's Previous, we execute Next), and finally cancel the event, so that the original Next or Previous is skipped in favor of our reversed version. In any other case, we just return from the handler without doing anything more, letting the system go ahead with its normal handling.