0 Favourites

How to unfocus?

This forum is currently in read-only mode.
  • 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"?

  • Have an extra editbox outside the layout and when you unfocus one of the main editboxes,focus that editbox.

    Here's an example: 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.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • shadowlord

    Thank you for your answer <img src="smileys/smiley1.gif" border="0" align="middle" />

    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.

  • Here are two other ways.

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

    2. If you want to use python:

    import ctypes
    hwnd=ctypes.windll.user32.GetActiveWindow()
    ctypes.windll.user32.SetFocus(hwnd)
  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)