First keystroke lost when replacing Windows Shell with a Windows Forms application

I have successfully replaced the Windows shell according to the approach outlined in this SO question .

However, I found that the first keystroke is lost and a little annoying to the user. The solution we tried was to activate the form in the OnShown event:

private void OnShownLoginForm(object z_sender, EventArgs z_e) { Activate(); m_loginTextBox.Focus(); } 

But this did not solve the problem. Do you have any information about what is happening?

+4
source share
3 answers

You can try using the System.Windows.Forms.SendKeys Class ( MSDN Documentation ) to send a keystroke event to the form when in the "Form Load" event. If this does not help, try sending keyboard events to the Form.Shown event, since Form.Shown is the last event in the process of running the form.

0
source

It looks like something caused, perhaps, by another control that gets focus in the first place. Is there taboring in the text box and can you set it to 0? Then the focus should be on it after loading the form.

Otherwise, try to create a new form for testing, it really does not play.

0
source

I donโ€™t know if this is related, but I had a similar problem when the tabindex property of the web form did not work by pressing the TAB key, after focusing on the first input when loading the page, until the user first clicked on the form with the mouse.

I did not have access to the source code, so I tried to solve it using javascript.
Before the first mouse click, all keystrokes, including the TAB key, triggered a keystroke event, the TAB key was not detected by pressing the / keyup key when the page loaded.

I found out that the TAB key triggered a key press event, and I could access the key code through it. just by logging a keystroke event and manually switching to the next input with jQuery processed. after the first mouse click, the form behaved as expected, the TAB key was no longer infected with the keypress event.

here is a sample code:

 function tabNext(e){ if(e.keyCode == 9){ // do work } } $('input').keypress(tabNext); 
0
source

All Articles