[RESOLVED] Sendkeys: send LWin key
Hello,
I am trying to send the windows key (the one with the flag on) using sendkeys on the click of the button.
This doesn't seem to be working:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendKeys.Send(Keys.LWin)
End Sub
Any help would be much appreciated.
Thanks in advance,
Harry.
Re: Sendkeys: send LWin key
Well honestly I'm not to fond of the SendKeys approach. If all you're trying to accomplish is to show the start menu then I would suggest trying this.
Code:
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As IntPtr, ByVal bScan As IntPtr, ByVal dwFlags As IntPtr, ByVal dwExtraInfo As IntPtr)
Private Const VK_STARTKEY = &H5B
Private Const KEYEVENTF_KEYUP = &H2
Private Const KEYEVENTF_KEYDOWN = &H0
Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call keybd_event(VK_STARTKEY, 0, KEYEVENTF_KEYDOWN , 0)
Call keybd_event(VK_STARTKEY, 0, KEYEVENTF_KEYUP, 0)
End Sub
Either way I'm sure this code snippet can be easily modified to suit your needs.
Re: Sendkeys: send LWin key
Thank you!
That works brilliantly. :)
Just wondering, is there a way of getting the names and locations of each of the shortcuts on the Start Menu?
Thanks,
Harry
Re: Sendkeys: send LWin key
Possibly, but they wouldn't involve opening the menu first. Might I venture to suggest that you may be going all round the houses? What exactly are you wanting to do?
Re: Sendkeys: send LWin key
SendKeys send string, so this SendKeys.Send(Keys.LWin) actually will send the code of Keys.LWin.
There is no special string to send Win key, but you can emulate by sending Ctrl+Esc, so try this
Code:
SendKeys.Send("^{Esc}")
Re: Sendkeys: send LWin key
Thanks for all of your help. :)
Re: Sendkeys: send LWin key
Quote:
Originally Posted by
4x2y
SendKeys send string, so this SendKeys.Send(Keys.LWin) actually will send the code of Keys.LWin.
There is no special string to send Win key, but you can emulate by sending Ctrl+Esc, so try this
Code:
SendKeys.Send("^{Esc}")
Nah, that don't work for the same reason that the original code didn't. SendKeys sends direct to the current active application. The system won't respond because the system never receives the message. If it's on a button click event then, by definition it sends to the form on which the button is placed.
Re: [RESOLVED] Sendkeys: send LWin key
Quote:
Nah, that don't work for the same reason that the original code didn't. SendKeys sends direct to the current active application. The system won't respond because the system never receives the message. If it's on a button click event then, by definition it sends to the form on which the button is placed
No, it is work fine, when put a button on the form and click on it, the start menu popup.
Re: [RESOLVED] Sendkeys: send LWin key
Quote:
Originally Posted by
4x2y
No, it is work fine, when put a button on the form and click on it, the start menu popup.
In every situation, regardless of the number of other applications running, or when another application is running "Always On Top"? Anyway, my mileage is completely different. Never works. The keybd_event method never not works so I'll be sticking with it.
Re: [RESOLVED] Sendkeys: send LWin key
Ctrl+Esc is a system wide hotkey, that is, it is always received by the system regardless of the number of applications running, or any of them is running "Always On Top".