It seems like the intent here is to easily handle pushed and held events for any key on the keypad. The two if’s shown above aren’t a big deal but if you’re handling two states for each of 9 buttons that would get chaotic. You’re on the right track with switch but it is used a bit differently than shown.
Let’s try an on event block that can subscribe to all important events triggered by your keypad(s). Inside the on event block you can use a switch to react to the event based on the $currentEvent* system variables. To begin, I would just add a debug log in the on event block for each of these variables so that you can see which corresponds to pressed, held, button #1, etc. I don’t have experience with a keypad but I would try logging $currentEventAttribute, $currentEventUnit, and $currentEventValue.
Once you see what is available for triggering you would use it like this, where the cases are the values you expect to see for the switched variable.
switch ($currentEventAttribute)
case "pushed":
with RGB Bulb 1 Turn on
case "held":
with RGB Bulb 1 Turn off
end switch
If the on events doesn’t work out, you can mitigate the code repetition in multiple if’s by storing your keypad in a variable and using that variable in the if’s.