locked
Setting shortcut hotkey CTRL+ALT+CAPS LOCK not working RRS feed

  • Question

  • Hi,

    I'm trying to create a Desktop shortcut with hotkeys per powershell.

    $wshShellObject = New-Object -com WScript.Shell
    $wshShellLink = $wshShellObject.CreateShortcut("C:\Users\Public\Desktop\XX.lnk")
    $wshShellLink.TargetPath = "C:\Program Files (x86)\XX\XX.exe"
    $wshShellLink.IconLocation = "C:\Program Files (x86)\XX\XX.ico"
    $wshShellLink.Hotkey = "CTRL+ALT+CAPS LOCK";  #not working
    $wshShellLink.Save()

    Now i'm really struggling with the Hotkey. Probably because it contains a space.

    Value does not fall within the expected range.
    At line:1 char:1
    + $wshShellLink.Hotkey = "CTRL+ALT+CAPSLOK";  #not working
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], ArgumentException
        + FullyQualifiedErrorId : System.ArgumentException

    German shortcutnames ("STRG+ALT+FESTSTELL") and escaping do not work.

    Here's what i've already tried:

    $wshShellLink.Hotkey = "CTRL+ALT+CAPS"; #not working $wshShellLink.Hotkey = "Ctrl+Alt+Capslock"; #not working $wshShellLink.Hotkey = "Ctrl+Alt+Caps lock"; #not working $wshShellLink.Hotkey = "Ctrl+Alt+CapsLock"; #not working $wshShellLink.Hotkey = "Ctrl+Alt+CAPS-LOCK" ; # not working $wshShellLink.Hotkey = "Ctrl+Alt+NUM LOCK" ; # not working $wshShellLink.Hotkey = "Ctrl + Alt + C"; #not working ->space $wshShellLink.Hotkey = "Ctrl+Alt+SHIFT"; # working $wshShellLink.Hotkey = "CTRL+ALT+C"; #working $wshShellLink.Hotkey = "CTRL+ALT+F6"; # working $wshShellLink.Hotkey = "Ctrl+Alt+\`"Caps lock\`""; #not working $wshShellLink.Hotkey = "Ctrl+Alt+`"Caps lock`""; #not working

    ...yes, it has to be CTRL+ALT+CAPS LOCK because the users are used to...

    Any ideas?

    Greetings

    Wednesday, November 6, 2019 2:55 PM

Answers

  • Well - I was wrong. A little tracking of keycodes and I found that caps llock is a regular key and will work,

    See:

    escription      :
    otkey           : Alt+Ctrl+Captial
    conLocation     : ,0
    elativePath     :
    argetPath       : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    indowStyle      : 1
    orkingDirectory : C:\WINDOWS\SYSTEM32\WINDOWSPOWERSHELL\V1.0


    \_(ツ)_/

    • Marked as answer by cbochynek Thursday, November 7, 2019 8:17 AM
    Thursday, November 7, 2019 8:10 AM

All replies

  • Sorry but combinations without a key are not supported.  Combinations may be filtered by other apps. 

    TO test the syntax create a shortcut in GUI and edit it in code to display the working syntax.


    \_(ツ)_/

    Wednesday, November 6, 2019 6:39 PM
  • Hi,

    thanks for your reply.

    The primary idea was creating the shortcut with a Visual Studio Installation Project, but there's no possibilty to set shortcut keys. Asking google is really hard, because the search results only show the the visual studio shortcuts to compile,...

    So I tryied powershell.

    The combination CTRL+ALT+CAPS LOCK is working if you set it by right clicking to an existing Shortcut Properties -> Shortcut -> Shortcut key.

    I'm not sure what you mean with "create in GUI".

    Thursday, November 7, 2019 6:12 AM
  • Create a shortcut in the GUI using the shortcut wizard and then look at the contents of the file created.


    \_(ツ)_/

    Thursday, November 7, 2019 6:23 AM
  • Sry, still have no idea what you're talking about. Powershell has no GUI?  I found the fuction Start-Transcrit but this only logs the actions in this Powershell.

    Do I have to use an additional programm like PowerGUI?

    Thursday, November 7, 2019 6:52 AM
  • Do you know how to use Windows File Explorer? Do you now how to create a shortcut in FE? You can create shortcuts almost anywhere in Windows like the Start Menu, the Desktop and any file folder. Search for articles on how to create shortcuts in Windows.

    \_(ツ)_/

    Thursday, November 7, 2019 6:58 AM
  • Oh, i thought about something more complicated. Of course I tried this.

    Creating the shotcutkey in the GUI gives me the exact string i've used in my code "CTRL+ALT+CAPS LOCK", german Version "STRG+ALT+FESTSTELL", but these strings won't work in code, thats why I opened this thread.

    Thursday, November 7, 2019 7:17 AM
  • Like i posted above - you cannot use the caps lock key as a coommand key. The command key must be a real key and not a "SHIFT" key. All of the shift keys set flags in the keycode. Without a real key the keycode will never be sent with the flags so nothing will happen.

    The caps lock key has the name “CAPITAL” and should be the same in German as the internal names are fixed while the display name is in the current locales language.


    \_(ツ)_/

    Thursday, November 7, 2019 7:32 AM
  • Well - I was wrong. A little tracking of keycodes and I found that caps llock is a regular key and will work,

    See:

    escription      :
    otkey           : Alt+Ctrl+Captial
    conLocation     : ,0
    elativePath     :
    argetPath       : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    indowStyle      : 1
    orkingDirectory : C:\WINDOWS\SYSTEM32\WINDOWSPOWERSHELL\V1.0


    \_(ツ)_/

    • Marked as answer by cbochynek Thursday, November 7, 2019 8:17 AM
    Thursday, November 7, 2019 8:10 AM
  • Thank you very much. "CAPTIAL" is the solution!

    So this will create a Shortcut with icon and hotkey:

    $wshShellObject = New-Object -com WScript.Shell
    $wshShellLink = $wshShellObject.CreateShortcut("C:\Users\Public\Desktop\XX.lnk")
    $wshShellLink.TargetPath = "C:\Program Files (x86)\XX\XX.exe"
    $wshShellLink.IconLocation = "C:\Program Files (x86)\XX\XX.ico"
    $wshShellLink.Hotkey = "CTRL+ALT+CAPTIAL";
    $wshShellLink.Save()

    Thursday, November 7, 2019 8:17 AM