|
You last visited: Today at 22:06
Advertisement
VB.net Send Keys + Clicks without focus
Discussion on VB.net Send Keys + Clicks without focus within the .NET Languages forum part of the Coders Den category.
06/07/2015, 20:02
|
#1
|
elite*gold: 0
Join Date: Apr 2010
Posts: 733
Received Thanks: 511
|
VB.net Send Keys + Clicks without focus
Guten Abend,
Ich suche nach einem Weg Keys und Clicks in einem minimierten Programm zu emulieren.
Beispiel:
SendKeys.Send("A")
SendKeys.Send("F11")
Mouseclick at x,y
SendKeys.Send("F11")
Das Programm soll kein Focus bekommen also alles im Hintergrund erledigen.
Ich habe es bereits so versucht, aber es sendet ja nur einen Text und keine Keys:
Code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd As IntPtr, ByVal hWndChildAfterA As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
Const WM_SETTEXT As Integer = &HC
Private Sub BotGuildBank()
Dim destination As IntPtr = FindWindow(Nothing, "TITLE")
Dim destControl As IntPtr = FindWindowEx(destination, IntPtr.Zero, "Edit", Nothing)
SendMessage(destControl, WM_SETTEXT, IntPtr.Zero, "A")
End Sub
Hab google schon durchsucht, vielleicht weiß von euch ja jemand einen Rat ^^
|
|
|
06/07/2015, 20:06
|
#2
|
elite*gold: 50
Join Date: Sep 2012
Posts: 3,841
Received Thanks: 1,462
|
Code:
[DllImport("user32.dll", CharSet = CharSet.None, ExactSpelling = false, SetLastError = true)]
private static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam);
Nach jedem aufruf:
Code:
PostMessage((int)handle, 0x0006, 0, 0);
|
|
|
06/09/2015, 18:28
|
#3
|
elite*gold: 724
Join Date: Mar 2011
Posts: 10,480
Received Thanks: 3,319
|
General Coding -> .NET Languages
#moved…
|
|
|
06/12/2015, 19:09
|
#4
|
elite*gold: 0
Join Date: Mar 2014
Posts: 2,790
Received Thanks: 6,658
|
> SendKeys im Minimierten Fenster.
Code:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
End Function
<DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function EnumChildWindows(ByVal WindowHandle As IntPtr, ByVal Callback As EnumWindowProcess, ByVal lParam As IntPtr) As Boolean
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Sub GetClassName(ByVal hWnd As System.IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer)
End Sub
Public Shared Function GetChildWindows(ByVal ParentHandle As IntPtr) As IntPtr()
Dim ChildrenList As New List(Of IntPtr)
Dim ListHandle As GCHandle = GCHandle.Alloc(ChildrenList)
Try
EnumChildWindows(ParentHandle, AddressOf EnumWindow, GCHandle.ToIntPtr(ListHandle))
Finally
If ListHandle.IsAllocated Then ListHandle.Free()
End Try
Return ChildrenList.ToArray
End Function
Public Delegate Function EnumWindowProcess(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean
Private Shared Function EnumWindow(ByVal Handle As IntPtr, ByVal Parameter As IntPtr) As Boolean
Dim ChildrenList As List(Of IntPtr) = GCHandle.FromIntPtr(Parameter).Target
If ChildrenList Is Nothing Then Throw New Exception("GCHandle Target could not be cast as List(Of IntPtr)")
ChildrenList.Add(Handle)
Return True
End Function
Private Const WM_CHAR = &H102
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
e.SuppressKeyPress = True
For Each P As Process In Process.GetProcesses
If P.ProcessName = "notepad" Then
For Each I As IntPtr In GetChildWindows(P.MainWindowHandle)
Dim L As Integer = 256
Dim sb As New System.Text.StringBuilder(L)
GetClassName(I, sb, L)
If sb.ToString = "Edit" Then
For Each c As Char In TextBox1.Text
SendMessage(I, WM_CHAR, Asc(c), 0)
Next
SendMessage(I, WM_CHAR, Keys.Enter, 0)
TextBox1.Clear()
Return
End If
Next
End If
Next
End If
End Sub
End Class
MFG #Lucas#
|
|
|
|
Similar Threads
|
[VB]Send.Keys :(..! Please..! Error
10/14/2011 - .NET Languages - 7 Replies
Hi. Sen.keys error. Please help me. does not work in metin2 . :(
FORM
Public Class Form1
Dim Komut As New AutoItX3Lib.AutoItX3
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = Val(TextBox2.Text) * 200
Label1.ForeColor = Color.Green
Label1.Text = "ACIK"
|
[Request] How send clicks on minimized
10/11/2008 - CO2 Programming - 2 Replies
How send clicks on minimized in Visual C# ?
|
Source code to send clicks (Minimized)
09/09/2008 - CO2 Programming - 0 Replies
Well let an example of some functions in VB6 to send clicks and pfs to the screen.
They work with the client miniminized or in background.
It is a way that I have not seen used in the examples in the forum but I think it is the most effective.
Unfortunately not comment on the code but the idea is this:
Send messages BUTTONDOWN / BUTTONUP directly to the window handle control that contains the display or which contains buttons pf. not to the window pricipal Co
...
|
All times are GMT +2. The time now is 22:06.
|
|