script creation SendKeys Method

Page 1 of 2 12 LastLast

  1. xTL
    Posts : 396
    Windows 10 Pro 64-Bit
       #1

    script creation SendKeys Method


    Hello,
    I would appreciate if someone could assist me with creating a SendKeys script.

    I've spent a lot of time trying to make this happen but I not getting anywhere.

    Worth mentioning is that I have very little knowledge with creating scripts, but i'd like to learn.

    This is what i want to achive.

    Take the shortcut key that is in the image below and turn it into a script.




    This is my code.
    Code:
    set WshShell = WScript.SendKeys
    ("WScript.Shell")    
    WshShell.SendKeys("^")    
    WshShell.SendKeys("%")    
    WshShell.SendKeys("+{INS}")

    But my script contains wrong syntax.
    Not sure what I'm doing wrong.

    Reading from here
    https://docs.microsoft.com/en-us/pre...m=MSDN#remarks





    hgdfhdh




      My Computer


  2. Posts : 3,274
    Win10
       #2

    Try and save this as TEST.vbs
    Code:
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.SendKeys "^%{INSERT}"
    And to run it, double-click it, or use either of the following commands, using the "correct path" to where you save the script.
    CScript.exe "C:\FULL_PATH_TO_\TEST.vbs"
    or
    WScript.exe "C:\FULL_PATH_TO_\TEST.vbs"

    I am not very conversant with vbs scripts, but at least this will get you going.
    Last edited by das10; 21 Jan 2022 at 13:14.
      My Computers


  3. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #3

    You didn't create the object WshShell and I can see that das10 has already shown you how to do that.
    Your earlier use of + was incorrect because what that was trying to do for you was put the Shift key into the command.
    Your original code
    1 issued the command to press Ctrl
    then it
    2 issued the command to press Alt then it
    3 issued the command to press Shift-Insert
    [Shift-Insert pastes the clipboard contents]
    as a set of three separate actions.

    From the documentation, you would expect
    Ctrl-Alt-Ins
    WshShell.SendKeys ("^%{INSERT}")
    to work but there are known to be undocumented exceptions for SendKeys.
    Note that
    Ctrl-Alt-Del
    WshShell.SendKeys ("^%{DELETE}")
    is one such exception and, since Ctrl-Alt-Insert is or was used in remote management in place of Ctrl-Alt-Del, I would not be surprised to find that
    WshShell.SendKeys ("^%{INSERT}")
    is also an undocumented exception.

    You can use a different hotkey combination such as
    Ctrl-Alt-9
    Code:
    set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.SendKeys("^%(9)")


    But I am not at all clear about what you are trying to achieve. Why aren't you just trying to use a script that directly launches your application or one that directly runs your shortcut instead of setting up a shortcut's hotkey then trying to get a script to run the hotkey for the shortcut?

    All the best,
    Denis
      My Computer


  4. xTL
    Posts : 396
    Windows 10 Pro 64-Bit
    Thread Starter
       #4

    das10 said:
    Try and save this as TEST.vbs
    Code:
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.SendKeys "^%{INSERT}"
    And to run it, double-click it, or use either of the following commands, using the "correct path" to where you save the script.
    CScript.exe "C:\FULL_PATH_TO_\TEST.vbs"
    or
    WScript.exe "C:\FULL_PATH_TO_\TEST.vbs"

    I am not very conversant with vbs scripts, but at least this will get you going.
    Thank you das10, sadly this did not work.
    Perhaps the .vbs is the worng way to go when trying to use shortcut key?

    I want to be able to use other letters and numbers aswell, like A-Z | 0-9 ect...
    I'd appreciate advice on what to use instead.
    Last edited by xTL; 24 Jan 2022 at 15:25.
      My Computer


  5. xTL
    Posts : 396
    Windows 10 Pro 64-Bit
    Thread Starter
       #5

    Try3 said:
    You didn't create the object WshShell and I can see that das10 has already shown you how to do that.
    Your earlier use of + was incorrect because what that was trying to do for you was put the Shift key into the command.
    Your original code
    1 issued the command to press Ctrl
    then it
    2 issued the command to press Alt then it
    3 issued the command to press Shift-Insert
    [Shift-Insert pastes the clipboard contents]
    as a set of three separate actions.

    From the documentation, you would expect
    Ctrl-Alt-Ins
    WshShell.SendKeys ("^%{INSERT}")
    to work but there are known to be undocumented exceptions for SendKeys.
    Note that
    Ctrl-Alt-Del
    WshShell.SendKeys ("^%{DELETE}")
    is one such exception and, since Ctrl-Alt-Insert is or was used in remote management in place of Ctrl-Alt-Del, I would not be surprised to find that
    WshShell.SendKeys ("^%{INSERT}")
    is also an undocumented exception.

    You can use a different hotkey combination such as
    Ctrl-Alt-9
    Code:
    set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.SendKeys("^%(9)")


    But I am not at all clear about what you are trying to achieve. Why aren't you just trying to use a script that directly launches your application or one that directly runs your shortcut instead of setting up a shortcut's hotkey then trying to get a script to run the hotkey for the shortcut?

    All the best,
    Denis
    Yeah, I misunderstood the syntax.

    Thanks for the explanation :)
    I think I understand it a bit better now, I appreciate it Try3


    Why not use a script that directly launches your application or one that directly runs your shortcut....
    Well like I said, I have very little knowledge with creating scripts, I will gladly take advice or tips on best practice

    Basically what I want to achieve / have fully working is following commands via shortcut key
    (like in the SS i posted in the first)

    CTRL + ALT + INS
    CTRL + ALT + END
    CTRL + ALT + O

    But easier said then done...
      My Computer


  6. Posts : 16,932
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #6

    xTL said:
    Basically what I want to achieve / have fully working is following commands via shortcut key
    (like in the SS i posted in the first)
    CTRL + ALT + INS
    CTRL + ALT + END
    CTRL + ALT + O

    1 The syntax you want is
    Try3 said:
    You can use a different hotkey combination such as
    Ctrl-Alt-9
    Code:
    set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.SendKeys("^%(9)")
    which will work for the
    CTRL + ALT + O example.


    2 Use das10's syntax for the CTRL + ALT + END example to see if it works.
    das10 said:
    Code:
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.SendKeys "^%{INSERT}"

    3 I do not expect das10's syntax to work for the CTRL + ALT + INS example. das10 is using the syntax correctly but I would not be surprised to find that that particular combination is an undocumented exception that cannot be made to work at all.




    Try3 said:
    But I am not at all clear about what you are trying to achieve. Why aren't you just trying to use a script that directly launches your application or one that directly runs your shortcut instead of setting up a shortcut's hotkey then trying to get a script to run the hotkey for the shortcut?
    4 What are you trying to do?
    - Launch an application?
    - Run a specific shortcut to launch an application?
    Do please note that I am not asking how you are trying to do it - This is addressed in your OP & your later post
    xTL said:
    Basically what I want to achieve / have fully working is following commands via shortcut key
    (like in the SS i posted in the first)
    I'm trying to find out what the desired end result is.

    5 If you post what you are trying to run/launch then include its full path & filename so suggestions can be made.

    6 Why are you trying to use a script to do this when a shortcut could do it instead?


    All the best,
    Denis
      My Computer


  7. xTL
    Posts : 396
    Windows 10 Pro 64-Bit
    Thread Starter
       #7

    Try3 said:
    1 The syntax you want is

    which will work for the
    CTRL + ALT + O example.


    2 Use das10's syntax for the CTRL + ALT + END example to see if it works.



    3 I do not expect das10's syntax to work for the CTRL + ALT + INS example. das10 is using the syntax correctly but I would not be surprised to find that that particular combination is an undocumented exception that cannot be made to work at all.






    4 What are you trying to do?
    - Launch an application?
    - Run a specific shortcut to launch an application?
    Do please note that I am not asking how you are trying to do it - This is addressed in your OP & your later post
    I'm trying to find out what the desired end result is.

    5 If you post what you are trying to run/launch then include its full path & filename so suggestions can be made.

    6 Why are you trying to use a script to do this when a shortcut could do it instead?


    All the best,
    Denis
    Currently the code you guys gave me does this once the script is executed for some weird reason.
    script creation SendKeys Method-15t531251.png

    Well I didn't want to take up too much of everyone's time,
    so I was hoping there would be a simple way to do this, but turns out it isn't...


    but okey since you ask, I'll explain.

    I want to be able to trigger a task via Task Scheduler when a simple shortcut key is pressed via script.
    OBS Studio is one of the applications I wish to have working.
    shortcut key for that is CTRL + ALT + O, then i want to be able to start / stop the stream by pressing,
    CTRL + ALT + HOME
    or
    CTRL + ALT + INS
    or
    CTRL + ALT + PAGE UP / DOWN / END.
    Anyone of these commands would work for me....

    I have it mapped in obs itself via hotkeys.

    Perhaps something like this

    script creation SendKeys Method-osmethong.png

    OBS Studio is installed in, "‪C:\Program Files (x86)\obs-studio\bin\64bit\obs64.exe"
      My Computer


  8. Posts : 21,421
    19044.1586 - 21H2 Pro x64
       #8

    I wouldn't have thunk this, but

    1. Moved (actually copied) my CTRL-ALT-INS newly assigned shortcut to my desktop and it still didn't work
    2. I rebooted my PC, and guess what ........... it worked
      My Computer


  9. Posts : 21,421
    19044.1586 - 21H2 Pro x64
       #9

    I actually tried CTRL-ALT-Z and that didn't work either until I kicked the PC in the xSS/rebooted.
      My Computer


  10. xTL
    Posts : 396
    Windows 10 Pro 64-Bit
    Thread Starter
       #10

    sadly restarting my pc does not help at all with the commands, does not work...
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 10:29.
Find Us




Windows 10 Forums