Looks like your buttons are indeed being sent as keys instead of controls. You can remap this in LSX by going to MIDI setup, scroll down to control 48 (for example) in the LSX Action column, and change type to key (and make sure key# is also 48). Now, incoming key messages should be treated as controller change messages (for key 48), so you can use them with the midi(48) expression. Selecting Control 48 and clicking Automap then hitting the button on your MIDI controller should have the same result.
Maybe there is a way to do this in your MIDI controller system, whatever you think is easiest to do.
If you like keyboard() more, or your MIDI button doesn't stay active, or whatever, you can use an expression like this:
Code:
a = keyboard(17);
if(bnot(equal(b, a)) * a , assign(c, 1-c), 0);
b = a;
result=c
In this code, "bnot(equal(b, a))" detects if you pressed or released the control key (so in this part of the expression, a and b would be different). This gets multiplied by a so it only works when you press the control key, not when you release it. If this condition is true (= equal to one, there are no booleans in LSX, that's why you can multiply instead of doing AND for example) then it assigns 1 to c if it is 0 or vice versa. The result is then c.