Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

using sendmessage to send ALT+ k to an app

Posted on 2003-10-29
7
Medium Priority
?
645 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

604 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