Solved

using sendmessage to send ALT+ k to an app

Posted on 2003-10-29
7
631 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 100 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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

729 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