?
Solved

using sendmessage to send ALT+ k to an app

Posted on 2003-10-29
7
Medium Priority
?
635 Views
Last Modified: 2011-09-20
can someone provide code to send the keystrokes alt + k to an app using sendmessage?
0
Comment
Question by:lilkiddoe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 400 total points
ID: 9647509
We can use this

Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

keybd_event 18, 0, 0, 0
keybd_event 75, 0, 0, 0
keybd_event 18, 0, &h2, 0
keybd_event 75, 0, &h2, 0

Thanks & Cheers
0
 
LVL 48

Assisted Solution

by:Mikal613
Mikal613 earned 400 total points
ID: 9647523
SendMessage Cannot do what you want you have to use PostMessage:

Here is also some code that I have used to simulate keystrokes, this emulates exactly what windows does when it sends keyboard messages to applications:

Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Sub SendKeystroke(KeyCode As Long, hWnd As Long)

Dim ScanCode As String

ScanCode = Hex(MapVirtualKey(KeyCode, 0))     ' Get scancode for key
ScanCode = String(2 - Len(ScanCode), "0") & ScanCode    ' Pad with zeros to get 2 digit number...

PostMessage hWnd, WM_KEYDOWN, KeyCode, CLng("&H00" & ScanCode & "0001")
PostMessage hWnd, WM_KEYUP, KeyCode, CLng("&HC0" & ScanCode & "0001")

End Sub

I your case call like:  call SendKeystroke(VBKey7, Child)

Michael Mann

0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9647530
If you want to use sendmessage,
Then get the handler for the app first

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
const VK_ALT = &HD
const VK_K = &H4B

dim hwnd as object
hwnd = findwindow(...) 'use spy++ to get the class and window name
sendmessage (hwnd, VK_ALT+VK_K, vbbullstring, vbnullstring)
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9647550
call SendKeystroke(VBAltMask, Child)
call SendKeystroke(VBKeyK, Child)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question