Resolved SendKeys on the WinKeys button

Pixel-Ink

Member
Joined
Jun 12, 2023
Messages
13
Programming Experience
5-10
I have looked at MS's list of available send keys on their site, but they don't seem to have one listed for the actual Windows Key.

The only solution I found was....

VB.NET:
SendKey.Send("^{ESC}")

However, the key strokes to show the desktop is Winkey+D
But, I can't seem to make using the ^{ESC} work with the letter "D"

VB.NET:
SendKey.Send("^{ESC}(d)")

All I get is the Start menu popping up.

So, exactly how do I simulate "Winkey+D" with SendKeys???

Any input will be greatly appreciated.
 
Last edited:
Well, I did get around this by using winapi's to minimize all windows .But, I am still interested to know how to use a SendKeys for the Windows Key. Windows 10 uses that to open a lot of OS apps.
 
VB.NET:
Public Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const VK_LWIN = &H5B 'Left Windows Key WIN
Public Const VK_RWIN = &H5C 'Right Windows Key WIN


' left windows key down
keybd_event(VK_LWIN, 0, 0, 0)
' left windows key up
keybd_event(VK_LWIN, 0, 2, 0)
 
Last edited by a moderator:
VB.NET:
Public Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const VK_LWIN = &H5B 'Left Windows Key WIN
Public Const VK_RWIN = &H5C 'Right Windows Key WIN


' left windows key down
keybd_event(VK_LWIN, 0, 0, 0)
' left windows key up
keybd_event(VK_LWIN, 0, 2, 0)

I haven't checked to confirm but that code probably won't work as is in VB.NET. Most Windows API functions use 32-bit numbers and, while Long is 32 bits wide in VB6, it is 64 bits wide in VB.NET. If you see Windows API code using Long, it was most likely written for VB6 and you will likely need to change those data types to Integer. If you use Long and get an error message about a stack imbalance, that is most certainly the case.
 
I get this error...

1687713686657.png
 
Sorry, I didn't see it. I will make the changes. Thanks
 
I specifically mentioned that error message in post #4. Did you bother to read it and make the change I specified?

Okay... the Start Menu did pop up. But, I could already do that as I stated in my original post.
But, I don't see any code for the combination of WinKey+D (key) so I can minimize all windows.
That's what WinKey+D does.

Thanks
 
I got it to work.
I found some examples for the D key
Public Const VK_D As Byte = 68
Public Const KEYEVENTF_KEYUP As Integer = 2

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

' left windows key down
keybd_event(VK_LWIN, 0, 0, 0)
' left windows key up
keybd_event(VK_D, 0, 0, 0)
' Pressionar a tecla D
keybd_event(VK_D, 0, KEYEVENTF_KEYUP, 0)
'release einkey
keybd_event(VK_LWIN, 0, 2, 0)

End Sub

THANKS FOR ALL YOUR HELP!!!
 
All I get is the Start menu popping up

Windows key opens the start menu

Pressing Shift+Escape also opens the start menu

This does not mean that pressing windows key performs a shift+esc, nor is pressing shift+esc the same as pressing windows

Shift+esc,D as a sendkeys would just type D into the start menu opened by shift+esc, not perform a Windows+D
 
I already resolved this.
And BTW... SHIFT+ESC doesn't display the start menu. It closes the program you are currently running.
Only CTRL+ESC displays start menu.

Thanks
 
That's what I meant, sorry-- whenever i wrote "shift" I should have written "Ctrl"

The point I was trying to get across was that though both Windows and Ctrl+Esc do both open the start menu, it does not mean they're the same keys
 
Last edited:
Back
Top