I am having difficulty retrieving when a user keys in a [shift]+[key] combincation.
I want to append each key stroke to a text object.
This works fine for most keys but not for the keys accessed by pressing shift.
For example I want the user to enter 3+4=
I have attached a capx.
StringFromLastkeycode will always return "=" and not "+" if the person presses [shift]+"=" I would expect a "+" sign.
What I have tried:
TextBox - hidden text box works quite well until the user clicks elsewhere on the screen. They need to be free to click other buttons on the screen but when they continue typing the textbox no longer has focus.
Develop games in your browser. Powerful, performant & highly capable.
Have you tried setting the focus on the textbox every tick ?
spongehammer yes I tried every 0.1 second that but then the buttons stopped responding when clicked.
At the moment I am thinking I might have to have a series of
if [shift] and keycode is "=" then append "+"
which I was hoping to avoid.
Ashley, I would value your input if you can spare a mo - I know you are on holiday
I have revisted the textbox idea, I believe I may have given up on that too quickly. Working on solution now.
I think the best way would to be to create a textbox to capture user typing. Then you can act on the input with code like:
UserText = TextBox.Text
UserLen = Len(UserText)
compare expected length of input to UserLen and act accordingly
parse the string via mid(UserText,x) *note* my testing seemed to indicate 0 based index where to get the first character it was mid(string,0,1)
so to parse the text when you expect 3+4=7
if len(UserText)<>5 -> error
Arg1 = mid(UserText,0,1)
Arg2 = mid(UserText,2,1)
SyntaxCheck = mid(UserText,3,1)
if SyntaxCheck <> "=" -> error
then have 4 checks for operand to find = "+-/*"
calculate result via Arg1 and Arg2 and compare to Result
hope this is clear and helps ;)
Are your buttons Sprite buttons or HTML buttons. Sprite buttons wont take away focus from the textbox.
I hadn't had a chance to update. Yes, I got the concept of textbox working correctly. It turned out my initial failure was my own fault and I attributed to c2. I will fix up a demo capx tomorrow and leave it here for others who may have same need in the future.
Cheers Kosiam I will use your ideas regarding parsing.