I think this is simpler:
blah blah
Global key$
While True
Select EventID()
Case EVENT_KEYDOWN
key$=EventData()
Case EVENT_KEYUP
key$=""
Case EVENT_GADGETPAINT
blah blah
If key$="37" then x=x-1 ' Key Left
If key$="39" then x=x+1 ' Key Right
End Select
Wend