C#-App: Saving the previous focus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dantz
    New Member
    • Oct 2008
    • 71

    C#-App: Saving the previous focus

    hi everyone,

    I am loading a flash game(shockwave flash object) using the panel in c# Winforms. Everytime the game will need to let the player to input some text I want to provide a virtual keyboard. But my problem is how to identify the focus from that flash game. What API do i need to use to save that focus so I can paste the inputs from my virtual keyboard.


    I know this question can be easily seen when searched thoroughly, but I can't find the right combinations for the strings to search and time is running out for me. Please help me


    Thanks a lot in advance

    Dantz
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Are you coding your own virtual keyboard, or using the windows one?

    WHen I've used the Windows virtual keyboard the keystrokes automatically went to the last application that had focus before before using the keyboard.

    If you are making your own then when your application creates a new VirtualKeyboard instance/object then subscribe to whatever event you raise when a key is pressed.

    Comment

    • dantz
      New Member
      • Oct 2008
      • 71

      #3
      Thanks

      Thank you very much for the reply. Yes, I am coding my own keyboard. I forgot to tell that I also have a textbox in my virtual keyboard to make a preview of the input of the keyboard.

      I also found another solution by getting the handle of the flash player.

      In the form where the keyboard button was clicked (to show the virtual keyboard):

      Code:
      GameKeyboard newGameKB = new GameKeyboard (this.flashPlayer.Handle);
      
      newGameKB .Show();

      Then on the Keyboard form I used the "SetFocus" API coz i already have the handle from the flash player.

      Code:
      [DllImport("user32.dll")]
      
      public static extern IntPtr SetFocus(IntPtr hWnd);
      
      private IntPtr _prevHwnd = IntPtr.Zero;
      
      public GameKeyboard (IntPtr prevHandle)
      
      {
      
            if (prevHandle != null)
      
            {
      
                  prevHwnd = prevHandle;
      
            }
      
                  InitializeComponent();
      
      }
      
      private void KBKey_Done(object sender, EventArgs e)
      
      {
      
      this.Hide();
      
      SetFocus(prevHwnd);
      
      SendKeys.Send(this.txtKBOutput.Text);
      
      }

      I hope this solution would not have any problems

      Comment

      Working...