Solved

using sendmessage to send ALT+ k to an app

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

Independent Software Vendors: 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

733 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