How to report Enter or Return key press?

Find quick help here to get you started with Hollywood
Post Reply
NathanH
Posts: 9
Joined: Sun Jul 05, 2015 1:29 am

How to report Enter or Return key press?

Post by NathanH » 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

User avatar
airsoftsoftwair
Posts: 2962
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How to report Enter or Return key press?

Post by airsoftsoftwair » Tue Jul 07, 2015 12:26 am

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

NathanH
Posts: 9
Joined: Sun Jul 05, 2015 1:29 am

Re: How to report Enter or Return key press?

Post by NathanH » Tue Jul 07, 2015 4:46 am

Thanks very much!

Nathan

Post Reply