0
$\begingroup$

I am trying to make a textual interface that doesn't rely on the mouse in order to focus widgets. All I have is a TextInput widget and I want this to always be focused/active such that it doesn't need selecting by the user with the mouse in order to type, I want whatever the user types to be input.

I have got as far as making it so that the user only needs to hover their mouse over the widget in order to use it using:

co.owner['sys'].layout.input.system.focused_widget = co.owner['sys'].layout.input
co.owner['sys'].layout.input.just_activated = 1    

I can't however seem to find which attribute needs changing in order for the widget to always think the mouse is hovering over it,

co.owner['sys'].layout.input._hover = True

doesn't seem to do this.

I've also tried

co.owner['sys'].layout.input.activate()

but this constantly refreshes the input field so I can't type more than 1 letter.

Any thoughts?

$\endgroup$
0
$\begingroup$

I think I have managed to solve this by doing the following:

co = bge.logic.getCurrentController()

keyboard = co.sensors["textinputkeyboard"]

    for key,status in keyboard.events:
        if status == bge.logic.KX_INPUT_JUST_ACTIVATED:
            co.owner['sys'].layout.input._handle_key(key,False) #text will always be lower case
            if key == bge.events.ENTERKEY: #This is so the enter callback still works
                 co.owner['sys'].layout.on_input_enter(co.owner['sys'].layout.input)

The above will work so long as the mouse doesn't make the text input active, in which case every character will be typed twice. In order to avoid this I commented out line 472 of bgui/widget.py:

widget._handle_key(key, is_shifted)

I realized this is a bit messy, but it works! If anybody has a cleaner way of doing this (I'm certain there is!) hmu.

I found a clean solution to this: First, remove the if statement:

if self._hover:

from the _handle_key() method in bgui/widget.py.

Then include:

    co.owner['sys'].layout.input.system.focused_widget = co.owner['sys'].layout.input

So that the textinput widget is always focused

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.