How to report Enter or Return key press?
Posted: Mon Jul 06, 2015 6:03 am
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
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