1

I have a winform application in which I have a Virtual Keypad. The following code (with textBox1 as winform textbox works fine:

 protected void touchScreen1_OnUserControlButtonClicked(object sender, EventArgs e)
        {
            textBox1.Focus();
          InputSimulator inputSimulator = new InputSimulator();
          inputSimulator.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.NUMPAD1); 
        }

But problem is that I am going to be typing inside a textbox which is not a windows forms control. I will be typing in a textbox which is a part of webpage loaded in webbrowser. Therefore I have no context. I can not explicit shift the focus to it. What do I do? Everytime I click the virtual key I have designed, it takes the focus out of the textbox in webcontrol and therefore does not type.

SamuraiJack
  • 5,131
  • 15
  • 89
  • 195
  • [How to create a Button that can send keys to a conrol without losing focus - Virtual Keyboard](https://stackoverflow.com/q/36771882/3110834) – Reza Aghaei Dec 18 '17 at 09:45
  • @RezaAghaei How do you guys know all this stuff? Anyways, post it as an answer so I can mark it. – SamuraiJack Dec 18 '17 at 09:52
  • Try the solution and let me know if it solves your problem, then let me know to mark it as an exact duplicate. – Reza Aghaei Dec 18 '17 at 09:57
  • @RezaAghaei do duplicate marks have any bad effect on user account? If yes, your solution did not work. If no, your solution worked flawlessly :P – SamuraiJack Dec 18 '17 at 10:07
  • @RezaAghaei I tried your solution and it seems that it works well for buttons but it does not work for forms. I mean if by accident, I click anywhere on the vacant space between buttons , webbrowser loses focus. Even though I added `CommonFunctions.SetStyle(this., ControlStyles.Selectable, false);` – SamuraiJack Dec 18 '17 at 10:22
  • Nevermind, I figured out the solution to that on my own. (placed everything inside a panel) – SamuraiJack Dec 18 '17 at 10:26
  • 1
    No the duplicate doesn't have any bad impact. It just lets the other users know the question has been answered in another linked question. That's Why I voted up your question, because in future someone else also can have the same question. – Reza Aghaei Dec 18 '17 at 15:41
  • Well in that case your answer worked perfectly ! Thank you. – SamuraiJack Dec 18 '17 at 16:35

0 Answers0