Results 1 to 7 of 7

Thread: Sendkeys combinations

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    3

    Question

    I am trying to use sendkeys to send the ctl-alt-w combination. I know I can use parenthesis to send combinations but it only seems to work on two keys, not three. For instance, I can send ctl-w by using sendkeys "^(w)", but I don't know how to do ctl-alt-w. If anyone can help, I appreciate it. Thanks.

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Try this, can't test it right now, but I think it should work:
    Code:
    "^%(W)"

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    3
    Thanks, but that doesn't do it. ^%(w) will press and release the ctl key, then press and hold alt while pressing w. I need to press and hold the ctl key.

  4. #4
    Matthew Gates
    Guest
    Use the keybd_event API function.


    Code:
    Option Explicit
    
    Private Declare Sub keybd_event Lib "user32" (ByVal _
    bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As _
    Long, ByVal dwExtraInfo As Long)
    
    Private Const VK_MENU = &H12
    Private Const KEYEVENTF_KEYUP = &H2
    
    
    Private Sub Command1_Click()
    
        keybd_event vbKeyControl, 0, 0, 0
        keybd_event VK_MENU, 0, 0, 0
        keybd_event vbKeyW, 0, 0, 0
        keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0
        keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
        keybd_event vbKeyW, 0, KEYEVENTF_KEYUP, 0
    
    End Sub

  5. #5
    Megatron
    Guest
    Or send the WM_KEYDOWN message.
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_KEYDOWN = &H100
    Usage:
    Code:
    SendMessage hwnd_of_window, WM_KEYDOWN, vbKeyControl, 0
    SendMessage hwnd_of_window, WM_KEYDOWN, vbKeyMenu, 0
    SendMessage hwnd_of_window, WM_KEYDOWN, vbKeyW, 0

  6. #6
    Matthew Gates
    Guest
    Megatron, after sending a WM_KEYDOWN message, wouldn't you have to release the keys as well?


    Code:
    Private Declare Function SendMessage _
    Lib "user32" Alias "SendMessageA" (ByVal hwnd As _
    Long, ByVal wMsg As Long, ByVal wParam As Long, _
    lParam As Any) As Long
    
    Private Const WM_KEYDOWN = &H100
    Private Const WM_KEYUP = &H101

    Usage


    Code:
    SendMessage hwnd_of_window, WM_KEYDOWN, vbKeyControl, 0
    SendMessage hwnd_of_window, WM_KEYDOWN, vbKeyMenu, 0
    SendMessage hwnd_of_window, WM_KEYDOWN, vbKeyW, 0
    
    SendMessage hwnd_of_window, WM_KEYUP, vbKeyControl, 0
    SendMessage hwnd_of_window, WM_KEYUP, vbKeyMenu, 0
    SendMessage hwnd_of_window, WM_KEYUP, vbKeyW, 0

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Posts
    3
    Thank you Matthew. Keybd_event API works beautifully.

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