Search code examples
vbawindowsbatch-filecmdsendkeys

Batch file hold shift key to hightlight


we run WinSQL with DB2's begin and end statements. We have multiple scripts in one file. I was wondering if there was a way to hold down shift with SendKeys to use the right arrow/down arrows to highlight the text I want to run. Does it need a loop? And how do I do a 5 second delay before it starts so I can switch the windows when I run it? I tried:

set /P "=Wait and send a command: " < NUL
ping -n 1 -w 1 127.0.0.1 > NUL
%SendKeys% "^{RIGHT}"

for the highlighting, multiple times, but it forgets about the shift key and just moves right multiple times.

Thanks


Solution

  • Try this for your sendkeys.

    Example

    %SendKeys% "+{right}"
    

    ^ is for CTRL key rather than shift.

    Then for delay try cmd command timeout /t 5

    On another note since you're using vbs also, you can use that to switch your windows as well.

    Dim ObjShell :Set ObjShell = CreateObject("Wscript.Shell")
    ObjShell.AppActivate("Notepad")