Hi,
Here's an example on clicking keys for the windows calculator
Easily to adjust for your own purposes.
br
DCA
-----------
VERSION 5.00
Begin VB.Form Form1
Caption = "Button Example"
ClientHeight = 3060
ClientLeft = 165
ClientTop = 735
ClientWidth = 3480
Icon = "Form1.frx":0000
LinkTopic = "Form1"
ScaleHeight = 3060
ScaleWidth = 3480
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmd_2
Caption = "2"
Height = 495
Left = 2040
TabIndex = 1
Top = 1680
Width = 495
End
Begin VB.CommandButton cmd_1
Caption = "1"
Height = 495
Left = 720
TabIndex = 0
Top = 1680
Width = 495
End
Begin VB.Label Label1
Caption = "Open the windows calculator and then press the buttons on this form to press the number one or 2 on the calculator."
Height = 975
Left = 240
TabIndex = 2
Top = 240
Width = 2895
End
Begin VB.Menu button_menu
Caption = "Menu"
Begin VB.Menu button_about
Caption = "About"
End
Begin VB.Menu button_exit
Caption = "Exit"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmd_1_Click()
Dim hWnd As Long ' receives handle to the found window
Dim ChildID As Long
Dim Nul As Integer
Dim lParam As Long
Dim nRtn As Long
Dim Btn As Integer, T As String, Pos As Integer
Dim Length As Integer
hWnd = FindWindow(vbNullString, "Calculator")
If hWnd = 0 Then
Debug.Print "Calculator is not running."
Else
'Now to use some apis
hWnd = GetDesktopWindow() 'Get Desktop handle
hWnd = GetWindow(hWnd, GW_Child) 'Find Child Windows of Desktop
Do
If hWnd = 0 Then Exit Do 'No (more) matches found
Length = GetWindowTextLength(hWnd) 'Find out how long the text in this window is
T = Space$(Length + 1) 'Allocate buffer space
Length = GetWindowText(hWnd, T, Length + 1)
Pos = InStr(1, T, "Calculator", 1)
If (Pos > 0) Then
hWnd = GetWindow(hWnd, GW_Child)
Do
If hWnd = 0 Then Exit Do
Length = GetWindowTextLength(hWnd)
T = Space$(Length + 1) 'Allocate buffer space
Length = GetWindowText(hWnd, T, Length + 1)
If InStr(UCase$(T), "1") Then
'This is the handle we want
ChildID = GetWindowLong(hWnd, GWL_ID)
Nul = SendMessage(GetParent(hWnd), WM_COMMAND, ChildID, ByVal CLng(hWnd))
Exit Sub 'Exit the do loop
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT) 'Keep looking
Loop
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT) 'Keep looking
Loop
End If
End Sub
Private Sub cmd_2_Click()
Dim hWnd As Long ' receives handle to the found window
Dim ChildID As Long
Dim Nul As Integer
Dim lParam As Long
Dim nRtn As Long
Dim Btn As Integer, T As String, Pos As Integer
Dim Length As Integer
hWnd = FindWindow(vbNullString, "Calculator")
If hWnd = 0 Then
Debug.Print "Calculator is not running."
Else
'Now to use some apis
hWnd = GetDesktopWindow() 'Get Desktop handle
hWnd = GetWindow(hWnd, GW_Child) 'Find Child Windows of Desktop
Do
If hWnd = 0 Then Exit Do 'No (more) matches found
'Find out how long the text in this window is
Length = GetWindowTextLength(hWnd)
T = Space$(Length + 1) 'Allocate buffer space
Length = GetWindowText(hWnd, T, Length + 1)
Pos = InStr(1, T, "Calculator", 1)
If (Pos > 0) Then
hWnd = GetWindow(hWnd, GW_Child)
Do
'Find out how long the text in this window is
If hWnd = 0 Then Exit Do
Length = GetWindowTextLength(hWnd)
T = Space$(Length + 1) 'Allocate buffer space
Length = GetWindowText(hWnd, T, Length + 1)
If InStr(UCase$(T), "2") Then
'This is the handle we want
ChildID = GetWindowLong(hWnd, GWL_ID)
Nul = SendMessage(GetParent(hWnd), WM_COMMAND, ChildID, ByVal CLng(hWnd))
Exit Sub 'Exit the do loop
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT) 'Keep looking
Loop
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT) 'Keep looking
Loop
End If
End Sub
Private Sub Form_Load()
frmSplash.Show
frmSplash.Timer1.Enabled = True
End Sub
Private Sub button_about_Click()
frmSplash.Show
End Sub
Private Sub button_exit_Click()
Unload Me
End Sub