Okay. I found one function called SIM_KEY (Not documented in Karel programming manual ) which does this. I tested it in roboguide and it works. There are two arguments for this function. Unfortunately, I dont know what the first argument is (Its a string, maybe someone knows what it is). The second argument is the function key number F1 to F5 which is mapped to 129 to 134.
Does SIM_KEY require a specific library to run? if so could you let me know which one you're using please.