• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 560
  • Last Modified:

Alternative to SendKeys

I need to control a menu in an external app.

SendKeys "%C" & "H"
SendKeys "%C" & "x"

does not always work.

I have the Window Handle, which means I can get the Menu Handle. How can I use PostMessage or SendMessage to do this?

Neal Hartman
Neal Hartman
  • 2
1 Solution
I believe you would use SendMessage with WM_CHAR... ie.

    iChar = Asc("A")  ' ansi value
    nRtn = SendMessage(hTxtLabel, WM_CHAR, iChar, 1)

This would be a good site to look at:

You could always use the keybd_event API to do stuff like that...

Public Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Good luck.
Neal HartmanAuthor Commented:
You put me in the right direction.
Acually it is:

Dim M1 As Long
Dim M2 As Long
Static sExit As Long
Static sHangUp As Long

    M1 = GetMenu(MainHwnd)
    M2 = GetSubMenu(M1, 0)
    sExit = GetMenuItemID(M2, 12)
    sHangUp = GetMenuItemID(M2, 11)

        PostMessage MainHwnd, WM_COMMAND, sHangUp, 0
        PostMessage MainHwnd, WM_COMMAND, sExit, 0

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now