How do i use a variable to press a key with robot class

Still not sure I get what you want but I guess you are looking for the keyPressed() function.