Results 1 to 9 of 9

Thread: How do I activate keyboard shortcuts?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2014
    Posts
    23

    Exclamation How do I activate keyboard shortcuts?

    Okay, so I figured out a while ago how to do something like this:

    Code:
    set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.SendKeys "Hey, I need some help!"
    Is there any way I can use the same .SendKeys command to activate keyboard shortcuts such as Ctrl+Alt+Del or Win+L or Fn+F5 etc?
    Last edited by techaddict; Mar 26th, 2014 at 12:20 PM.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How do I activate keyboard shortcuts?

    The SendKeys method doesn't recognize either Windows key or Function key so you won't be able to activate keyboard shortcuts such as Win+L or Fn+F5. You can, however, simulate pressing the three-finger salute with:

    Code:
    CreateObject("WScript.Shell").SendKeys "^%{DEL}"
    You may want to consult the SendKeys method for more info on keys it recognizes.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2014
    Posts
    23

    Re: How do I activate keyboard shortcuts?

    Thanks. Do you know how else I could simulate Win+L? That's the lock screen shortcut for Windows 8 and I'd love to be able to link a .vbs or something of it to voice commands

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How do I activate keyboard shortcuts?

    Don't know if this will work in Windows 8:

    Code:
    CreateObject("WScript.Shell").Run "rundll32.exe user32.dll,LockWorkStation"
    I got that from Rob van der Woude's Scripting Pages site.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2014
    Posts
    23

    Re: How do I activate keyboard shortcuts?

    Tried both. The one for locking the computer works perfectly, Thanks! The other one didn't...

  6. #6
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How do I activate keyboard shortcuts?

    If you're done with this thread, please don't forget to mark it Resolved! Thanks!

    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Mar 2014
    Posts
    23

    Re: How do I activate keyboard shortcuts?

    Quote Originally Posted by Bonnie West View Post
    If you're done with this thread, please don't forget to mark it Resolved! Thanks!

    Yep, I will, I'd still like to know how to activate ctrl+alt+del though...

  8. #8
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How do I activate keyboard shortcuts?

    Quote Originally Posted by techaddict View Post
    ... I'd still like to know how to activate ctrl+alt+del though...
    Didn't the code in post #2 work for you?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2014
    Posts
    23

    Re: How do I activate keyboard shortcuts?

    Quote Originally Posted by techaddict View Post
    Tried both. The one for locking the computer works perfectly, Thanks! The other one didn't...
    Unfortunately, no...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width