none
controlling the focus RRS feed

  • Question

  • Hi.
    Does anyone know how can I make a control work without recieving the focus?
    The thing is that I'm trying to simulate a kyboard (on a UserControl) which is added to a form. Whenevet a key is clicked, I use the SendKeys.SendWait method to simulate a keystroke. In order to process the simulated keystroke, the recieving form should be in focus. To achieve this, I use the SetFocus API function with the handler of the recieving form. So far so good - it all works fine except for the slight occasional control bar flicker when changing the focus.
    So - is there a way to avoid all that focus transfer?
    Friday, November 24, 2006 10:45 AM

Answers

  • You'll need to give up on SendKeys if you want to avoid the focus problem.  You could send the WM_KEYDOWN and WM_KEYUP messages directly to the control that last had the focus on the form.  Use the SendMessage() API function.  Set the WParam argument to value of one of the Keys enums.  Don't worry about the LParam.  You can find the last active control with Form.ActiveControl. 
    Friday, November 24, 2006 1:57 PM
    Moderator