Dealing with Key-Event ... for later showkeyboad() use

Find quick help here to get you started with Hollywood
Post Reply
LarsB
Posts: 72
Joined: Sat May 06, 2017 4:37 pm

Dealing with Key-Event ... for later showkeyboad() use

Post by LarsB »

Hi,
I am just porting a little game to Android,

The last thing I gotta do is taking the name from ShowKeyboard(). Its a keyevent, as far as I understood.
So I wrote a very small PC program first program to get to there. The entry should stop when I press return.

And here I stuck a little bit. Can you suggest something?

Code: Select all

@DISPLAY {ScaleMode = #SCALEMODE_AUTO, FitScale = True, HideTitleBar = True}
	
Function p_HandlerFunc(msg)
  Switch(msg.action)
	
	Case "OnKeyDown":
	/* "User has pressed OnKeyDown" */
	If msg.key = "ESC" Then End
	If msg.key = "RETURN" Then End
	s$ = msg.key
	
        Print(s$)
 	
  EndSwitch
EndFunction

InstallEventHandler({OnKeyDown = p_HandlerFunc})

Repeat
WaitEvent
Until s$="ENTER" 
zylesea
Posts: 227
Joined: Tue Feb 16, 2010 12:50 am
Location: Westfalen/Germany
Contact:

Re: Dealing with Key-Event ... for later showkeyboad() use

Post by zylesea »

Here's my solution to enter to a string, including backspace and quitting on Return.Takes also care whether the keyboard actually is shown or hidden.

Code: Select all

Function p_enter_text(key$)  
(...)
Switch  key$
          Case "BACKSPACE"
            my_string$=UnleftStr(my_string$,1)
          Case "\n":
            If android$=1 Then hidekeyboard()
             kbd$=0
          Default
            If StrLen(my_string$)<sl$ Then my_string$=my_string$..key$  
(...)
endfunction            
I have a handler definitions for
OnkeyDown = p_HandlerFunc
HideKeyboard = p_HandlerFunc,

according part of the handler function

Code: Select all

Switch (msg.action)
   Case "OnKeyDown":   
   If kbd$=1 Then p_enter_text(msg.key)   
  Case "hidekeyboard":
   kbd$=0    
 endswitch
kbd$ is a variable to check whether the keyboard is shown or not. Maybe not requirerd, but seemed useful to me.

Hope this helps.
LarsB
Posts: 72
Joined: Sat May 06, 2017 4:37 pm

Re: Dealing with Key-Event ... for later showkeyboad() use

Post by LarsB »

Wow! :) Thank you very much. Great to have you Hollywooders around. So I can continue. :D
Post Reply