How to unfocus?

For questions about using Classic.

Post » Fri Feb 10, 2012 9:32 am

I very rarely ask for help, but I just can't figure this one out.
In a project I use some edit boxes, text boxes, panels and system buttons to present some statistics. The application also has a mini game integrated.
While the key controls for the mini game work fine, they at the same time control the buttons as soon as one of the system buttons was used. For example, space simulates a button click on the last button used.
While I can "unfocus" the edit boxes with "focus off", this totally messes up the key controls. Once "focus off" was used no pressed key is passed to the events any more, instead you just hear a system sound indicating that you click somewhere not supposed to.

How do I make the key controls work using the MouseKeyboard object, even when a button was clicked or an edit box was "unfocussed"?tulamide2012-02-10 09:33:25
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Feb 10, 2012 12:58 pm

Have an extra editbox outside the layout and when you unfocus one of the main editboxes,focus that editbox.
Here's an example: http://dl.dropbox.com/u/52670878/editboxFocus.cap
-Click the editbox to focus it, click outside of it to unfocus.

Or you can try and make a custom editbox using the text object.
I can't think of a simpler way.Someone should fix the editboxes.
B
6
S
1
G
1
Posts: 69
Reputation: 1,019

Post » Fri Feb 10, 2012 6:34 pm

@shadowlord
Thank you for your answer
I did exactly what you proposed too. I'm just not very satisfied with this solution, because it will fill that editbox with spaces all over the time, while space is pressed, which might lead to overloading the editbox (what is the maximum number of letters, 65535?)

But seeing that others have the same problem und use the same workaround leads me to think that it's ok for now. So thank you once again.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Feb 10, 2012 7:03 pm

Here are two other ways.

1. Destroying the EditBox or Button will restore the keyboard focus.

2. If you want to use python:
[code]import ctypes
hwnd=ctypes.windll.user32.GetActiveWindow()
ctypes.windll.user32.SetFocus(hwnd)[/code]R0J0hound2012-02-10 19:04:08
B
79
S
24
G
53
Posts: 4,728
Reputation: 40,219

Post » Sat Feb 11, 2012 2:21 am

Unless I am missing something, why don't You just use a 'focus' variable?
Set it to 1, if You want focus, and to 0 if You don't.
Then only allow the buttons to work, if something was pressed AND focus = 1.
B
3
G
1
Posts: 70
Reputation: 615

Post » Sun Feb 12, 2012 8:49 am

Thank you very much @ROJOhound, the workaround by destroying/recreating the objects is simple and effective. I will also keep the python example (the simplest solution in my view) for future projects, but this one is so small that I don't want to bloat it by adding Python.

@Shindoh
For two reasons:
1) Every button will be triggered by a key, no matter if you use a variable or not. You can only prevent the action, but the player will still see the button, e.g, in its pressed state when space is pressed. I don't want a reaction to any key press.

2) The mini game runs simultanously, it coexists with the statistics part, and the user may at any time use the buttons to change values or calculate new statistics, even while playing.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests