Solved

using sendmessage to send ALT+ k to an app

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now