none
How do i keep the focus on the textbox when the user clicks the mouse

    Question

  • I have a text only program (similar to an old TRS-80 game) that works fine - unless someone clicks somewhere on the screen.  Then the keyboard dies, and I cannot get it to regain focus without hitting the Tab key.  How can I get my program to either ignore all mouse input or switch focus back to the textbox so that I can process some keyboard input.
    Tuesday, June 28, 2016 1:50 PM

Answers

  • I am using Visual Studio 2015, c++, Windows Universal platform.  This is either a very low (newbie) question or a very high (design philosophy) question.  That is to say, in IOS you can either use Focus(), which lets the programmer decide which part of the screen should have focus, or just rely on your KeyUp(self, e) routine to catch all keystrokes whether or not there are some mouse clicks happening on the screen.  C++ has a Focus() command, but it is really a Boolean hasFocus(), not a true directive subroutine.  What I can't figure out is why a mouse click should kill the KeyUp() command. The timer still works, so the program is not hanging waiting for some response to the click event.  It's just such a bizarre way of handling key press events that I can't help thinking that I'm missing something obvious.

         Anyway, I "solved" my problem by creating a tiny button to accept a mouse click event, and making my text entry box as big as the whole screen.  Now any random clicks just send the focus to the proper place - unless the user is so unlucky as to hit the 4 pixel by 4 pixel button in the corner.  If he/she does that they are just out of luck, since the button will not return focus to the text box, and buttons don't accept keystrokes.

        I consider it answered, in a functional sort of way.

    Saturday, July 2, 2016 1:30 PM

All replies

  • Hi Drew2rich,

    Since Our forum is discussing about VS general question like how to set/configure Visual Studio and Visual Studio tools.

    And if you could tell me the development language and the application type then I will help to move you thread to the corresponding forum for better support.

    Thanks for your understanding.

    Best Regards,

    Lake Xiao

    Thursday, June 30, 2016 2:02 AM
    Moderator
  • I am using Visual Studio 2015, c++, Windows Universal platform.  This is either a very low (newbie) question or a very high (design philosophy) question.  That is to say, in IOS you can either use Focus(), which lets the programmer decide which part of the screen should have focus, or just rely on your KeyUp(self, e) routine to catch all keystrokes whether or not there are some mouse clicks happening on the screen.  C++ has a Focus() command, but it is really a Boolean hasFocus(), not a true directive subroutine.  What I can't figure out is why a mouse click should kill the KeyUp() command. The timer still works, so the program is not hanging waiting for some response to the click event.  It's just such a bizarre way of handling key press events that I can't help thinking that I'm missing something obvious.

         Anyway, I "solved" my problem by creating a tiny button to accept a mouse click event, and making my text entry box as big as the whole screen.  Now any random clicks just send the focus to the proper place - unless the user is so unlucky as to hit the 4 pixel by 4 pixel button in the corner.  If he/she does that they are just out of luck, since the button will not return focus to the text box, and buttons don't accept keystrokes.

        I consider it answered, in a functional sort of way.

    Saturday, July 2, 2016 1:30 PM
  • I think that a call to SetCapture() also would have accomplished the same thing.

    Glad you found a solution.

    Saturday, July 2, 2016 2:36 PM