Search code examples
keyboardnaturallyspeaking

How can I write a voice command in Dragon NaturallySpeaking that holds a key down for X seconds?


How can I write a voice command in Dragon NaturallySpeaking that holds a key down for X seconds?


Solution

  • The following voice command will hold the key CTRL for three seconds. You can change the key as well as how long the key is being hold down.

    ' Tested with Dragon NaturallySpeaking 12.5 Professional on Windows 7 SP1 x64 Ultimate
    ' From http://nuance-community.custhelp.com/posts/2cd74d2484
    ' Lindsay Adam
    ' www.pcbyvoice.com
    
    Declare Function keybd_event Lib "user32.dll" (ByVal vKey As _
    Long, bScan As Long, ByVal Flag As Long, ByVal exInfo As Long) As Long
    
    ' You can find all the virtual key codes in the following link:
    ' http://msdn.microsoft.com/en-us/library/ms927178.aspx
    Const VK_CTRL = 17
    
    Sub Main
        keybd_event(VK_CTRL,0,0,0)
        Wait(3)
        keybd_event(VK_CTRL,0,2,0)
    End Sub
    

    http://msdn.microsoft.com/en-us/library/ms927178.aspx (their robots.txt doesn't allow me to mirror their website with https://web.archive.org):

    enter image description here