Can someone tell mew how to send Shortcut keys in vb.net? The shortcut keys are {LEFTWIN} + {ADD} amd {LEFTWIN} + {SUBTRACT}. Tried SendKeys.Send it does not work.
You said you tried
SendKeys.Sned("KEY")
The correct is
SendKeys.Send("KEY")
Besides that, what key you are referring with "Leftwin" ?
Sorry for that, I never used Sendkeys, and I knew "LWIN" by Winkey...
Btw, Try using
SendKeys.Send(Keys.LWin)
SendKeys send string, so this SendKeys.Send(Keys.LWin) actually should send the code of Keys.LWin
Finally this worked for me :)
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 VK_SUBTRACT = &H6D
Private Const VK_ADD = &H6B
Private Const VK_ESCAPE = &H1B
Private Const KEYEVENTF_KEYUP = &H2
Private Const KEYEVENTF_KEYDOWN = &H
Call keybd_event(VK_STARTKEY, 0, KEYEVENTF_KEYDOWN, 0)
Call keybd_event(VK_ADD, 0, KEYEVENTF_KEYDOWN, 0)
Call keybd_event(VK_ADD, 0, KEYEVENTF_KEYUP, 0)
Call keybd_event(VK_STARTKEY, 0, KEYEVENTF_KEYUP, 0)
Key codes: http://vbcity.com/cfs-filesystemfile.ashx/__key/CommunityServer.Components.PostAttachments/00.00.11.85.52/Api.txt
EDIT The keybd_event is deprecated so I am moving to SendInput(). The first solution works best for me :-)
Sending LWin
is not possible through SendKeys.Send()
. In order to do so you have to P/Invoke the WinAPI's SendInput() function.
Here's a wrapper class I've created for that purpose:
EDIT (2019-09-20)
InputHelper
has since long been moved to its own library. The answer has been updated to reflect this change.Download InputHelper from GitHub:
https://github.com/Visual-Vincent/InputHelper/releases
Here's how you'd use it:
InputHelper.Keyboard.SetKeyState(Keys.LWin, True) 'Hold LWin.
InputHelper.Keyboard.PressKey(Keys.Add) 'Press the ADD key.
InputHelper.Keyboard.SetKeyState(Keys.LWin, False) 'Release LWin.