Hi,
I'm writing an RPN calculator that uses the keypad extensively. The Enter or Return key is used all of the time to enter numbers onto the stack. On the "IsKeyDown" help page it talks about the names to use for sensing special keys. The following code snippet senses all of the keypad keys on Windows, AROS, and OS3 except the Return or Enter key. What am I doing wrong? Thanks in advance for the help.
Nathan
;return and enter key are not reported
@DISPLAY {Title="Return & Enter Test", Color=#WHITE}
SetFontColor(#BLACK)
SetFont(#SANS,16)
Function p_DoKeys(msg)
Local key=UpperStr(msg.key)
Switch msg.action
Case "OnKeyDown"
If key="0" Or key="1" Or key="2" Or key="3" Or key="4" Or key="5" Or key="6" Or key="7" Or Key="8" Or key="9"
NPrint("Number " .. key .. " clicked.")
Else
Switch key
Case "BACKSPACE"
NPrint(key .. " clicked.")
Case "."
NPrint(key .. " clicked.")
Case "/"
NPrint(key .. " clicked.")
Case "*"
NPrint(key .. " clicked.")
Case "-"
NPrint(key .. " clicked.")
Case "+"
NPrint(key .. " clicked.")
Case "ENTER"
NPrint(key .. " clicked.")
Case "RETURN"
NPrint(key .. " clicked.")
EndSwitch
EndIf
EndSwitch
EndFunction
InstallEventHandler({OnKeyDown=p_DoKeys})
; wait for events
Repeat
WaitEvent
Forever
How to report Enter or Return key press?
- airsoftsoftwair
- Posts: 5446
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: How to report Enter or Return key press?
The "OnKeyDown" event handler reports return and enter as raw ASCII code. This is inconsistent with IsKeyDown() but is more convenient for text handling. So you just have to check for something like this:
Code: Select all
Switch msg.key
Case "\n":
NPrint("Got return or enter")
EndSwitch
Re: How to report Enter or Return key press?
Thanks very much!
Nathan
Nathan