Keyboard woes

Get help using Construct 2

Post » Tue Aug 06, 2013 11:12 pm

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.

B
37
S
9
G
5
Posts: 437
Reputation: 6,094

Post » Wed Aug 07, 2013 12:02 am

@czar

Have you tried setting the focus on the textbox every tick ?
B
47
S
16
G
9
Posts: 1,097
Reputation: 11,180

Post » Wed Aug 07, 2013 12:42 am

@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
B
37
S
9
G
5
Posts: 437
Reputation: 6,094

Post » Wed Aug 07, 2013 5:44 am

I have revisted the textbox idea, I believe I may have given up on that too quickly. Working on solution now.
B
37
S
9
G
5
Posts: 437
Reputation: 6,094

Post » Wed Aug 07, 2013 6:20 am

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)
Result= mid(UserText,4,1)
Operand= mid(UserText,1,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 ;)
B
5
Posts: 26
Reputation: 277

Post » Wed Aug 07, 2013 9:15 am

@czar

Are your buttons Sprite buttons or HTML buttons. Sprite buttons wont take away focus from the textbox.
B
47
S
16
G
9
Posts: 1,097
Reputation: 11,180

Post » Wed Aug 07, 2013 9:22 am

@Kosiam @spongehammer,

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.
B
37
S
9
G
5
Posts: 437
Reputation: 6,094


Return to How do I....?

Who is online

Users browsing this forum: rayolf, Yahoo [Bot] and 23 guests