how to m a Win+D action button visual basic ??

GR Kevin (Kzip)

Dani AI

Generated

A couple of clarifications based on the thread: , calling tsdiscon.exe will disconnect a Terminal Services/Remote Desktop session — it does not emulate the Windows "Show Desktop" (Win+D) action. , key‑hooking is for capturing global key events; it isn't needed if the goal is simply to make a button perform the Win+D effect.

Two practical approaches:

  • Quick and simple: use the Shell COM object to minimize all windows (this behaves like Win+M). It is not exactly the same as Win+D on all Windows versions, but it's easy to call from VB.NET:

    Dim sh = CreateObject("Shell.Application")
    sh.MinimizeAll()
  • Accurate (recommended): simulate the Win key + D. The supported API is SendInput; for quick testing you can use the older keybd_event. keybd_event is deprecated; prefer SendInput in production. A minimal keybd_event example (VB.NET P/Invoke + calls) looks like this:

    
    <System.Runtime.InteropServices.DllImport("user32.dll")>
    Private Shared Sub keybd_event(bVk As Byte, bScan As Byte, dwFlags As UInteger, dwExtraInfo As UIntPtr)
    End Sub

Const VK_LWIN As Byte = &H5B
Const VK_D As Byte = &H44
Const KEYEVENTF_KEYUP As UInteger = &H2

' press Win+D
keybd_event(VK_LWIN, 0, 0, UIntPtr.Zero)
keybd_event(VK_D, 0, 0, UIntPtr.Zero)
' release
keybd_event(VK_D, 0, KEYEVENTF_KEYUP, UIntPtr.Zero)
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, UIntPtr.Zero)



Links to the Windows docs: SendInput (recommended) and keybd_event (deprecated) — see the Microsoft API reference for details and full SendInput examples: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput and https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-keybd_event

Notes: prefer `SendInput` for reliability; use `Shell.Application.MinimizeAll` only if the exact Win+D toggle behavior is not required. Test on the target Windows version to confirm the side effects you expect.

Recommended Answers

All 2 Replies

Search for Key Hooking ...

use

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim processID As Integer

        processID = Shell("tsdiscon.exe", AppWinStyle.NormalFocus)



    End Sub

GR Kevin

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.