I am using a voice recognition add-on to Dragon NaturallySpeaking to create keystroke automations using my voice. The add-on exposes the VB function SendKeys
. I am aware that the shift key modifier (+
) can be combined with almost any other character(s), but I am not trying to combine the shift key with anything; I simply want to send a single shift keypress without anything else. Is this possible?
Some things I've tried:
SendKeys "+"
SendKeys "{Shift}"
Any ideas?
UPDATE:
Based on the article posted by user14797724, it's use of the keybd_event User32 library function, and the documentation for the System.Windows.Forms.Keys enumeration, I modified the code to use left shift. Here's the code:
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Public Module SendWinKey
Const KEYEVENTF_KEYDOWN As Integer = &H0
Const KEYEVENTF_KEYUP As Integer = &H2
Declare Sub keybd_event Lib "User32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInteger, ByVal dwExtraInfo As UInteger)
Public Sub Main()
keybd_event(CByte(Keys.LShiftKey), 0, KEYEVENTF_KEYDOWN, 0) 'press the left shift key down
keybd_event(CByte(Keys.LShiftKey), 0, KEYEVENTF_KEYUP, 0) 'release the left shift key
End Sub
End Module
I was hoping this would work for me but it appears that the scripting environment I am using does not support the Imports keyword and requires CLS-Compliant variables for an external call. I might be able to get around the Imports keyword problem by prefixing the appropriate types with their full namespace but does anybody have an alternative external call I might make that is CLS-Compliant? The UInteger type seems to be the one it doesn't like.
UPDATE 2:
I don't know what I was thinking when I put VBScript as one of my tags. I had tagged VBA but someone edited it out. As best I can tell the "language" I am using is a subset of Visual Basic. Here is a screenshot of the editor.
Yeah, what he said. I can see where you put some thought into your answer. I suggest that you add comments beside the 160 to explain where that comes from.