user32.dll hakkında ilk yazmaya karar verdiğimde bu konuların sonunun gelmeyeceğini tahmin edebildiğim için kategori açmıştım . şimdi o kategorideki ikinci yazımı yazmak istiyorum. ufak bir projede remote control olayını yapmak istediğm (sakın kendi pcnizi yonetmeyi denemeyin mutlaka bir server-client olsun )  bu olayda işimize yaricak tek EntryPoint mouse_event olacak. bu fonksiyon  windowsa mouse Down ve Mouse Up  mesajları gondermemize yarıyor. Down+Up=Click olacağından bize clik , double click , right click kapılarını da açmış oluyor.  bunu ilk once kendi pcmde denemeye kalktım ama mantıksızlık olduğunu anca pc donunca anladım (: ilk ekran goruntusu alma konumuzdaki fonksiyonu kullanarak ikinci monitorumden goruntu aldım oncelikle.  biraz eğlence oldu tabi monitor değişinceye kadar ana monitorden goruntu alıp yine ana monitordeki programcığımda bunu göstermeye çalıştım işte görüntü aşağıda (:

biraz bu görüntü ile eğlendikten sonra bir de bunlara click gondermeyi denedim  ve sonuç BUM :D click olayı ekranın aynı yerine click ettiği için bu benim programdaki clik olayıma geliyor ve click bir daha calışıyor bu da pcmin donmasına sebep oldu.

işte win apinin mouse eventlarıyla geliştirebileceğiniz sınıfım.

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
a
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
namespace WinApi
 
{
public class Mouse {
 
// user32.dll apisinin mouse_event EntriPointinden Yararlancaz.
 
[DllImport("user32.dll")]
 
private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);
 
// Onay Tanmlarmz
 
// -------------------
 
// Sol Down
 
public const UInt32 MouseEventLeftDown = 0x0002;
 
// Sol Up
public const UInt32 MouseEventLeftUp = 0x0004;
 
// Sa Down
public const UInt32 MouseEventRightDown = 0x0008;
 
// Sa Up
public const UInt32 MouseEventRightUp = 0x00016;
 
// Kk FOnksiyonumuzu yazalm tm mouse eventlar burdan geecek yani mouse_event'tan
private static void SendMouseEvent(UInt32 Button, uint x, uint y, System.IntPtr intptr)
 
{
 
mouse_event(Button, x, y, 0, new System.IntPtr());
 
}
 
// Down eventi gonderen fonksiyon. (Mouse Butonuna Basma. )
 
public static void SendDown(UInt32 Button, uint x, uint y)
 
{
 
// Cursoru tklamak istediimiz koordinatlara Konumlandryoruz.
Cursor.Position = new Point((int)x, (int)y);
 
// Olaymz Gonderiyoruz.
SendMouseEvent(Button, x, y, new System.IntPtr());
 
}
 
// Left Down Fonksiyonumuz.
public static void SendLeftDown(uint x, uint y)
 
{
 
SendDown(MouseEventLeftDown, x, y);
 
}
 
// Up Fonksiyonumuz.(Buton Brakma lemi)
public static void SendUp(UInt32 Button, uint x, uint y)
 
{
 
// Cursoru tklamak istediimiz koordinatlara Konumlandryoruz.
Cursor.Position = new Point((int)x, (int)y);
 
// Olaymz Gonderiyoryuz.
SendMouseEvent(Button, x, y, new System.IntPtr());
 
}
 
// Left Button Up Fonksiyonu (Sol Butonu Brakma ilemi)
public static void SendLeftUp(uint x, uint y)
 
{
 
SendMouseEvent(MouseEventLeftUp, x, y, new System.IntPtr());
 
}
 
// 1 basma + 1 brakma = 1 click olacandan click olaymz da bu ekilde gnderiyoruz.
 
public static void sendLeftClik(uint x, uint y)
 
{
 
SendLeftDown(x, y);
 
SendLeftUp(x, y);
 
}
 
// DoubleClick=2xClick (:
public static void SendDoubleClick(uint x, uint y)
 
{
 
sendLeftClik(x, y);
 
sendLeftClik(x, y);
 
}
 
}
 
}

3 Responses to “win apileri ile remote control yapalım (c# user32.dll)”

  1. [...] Menu MenuItemFromPoint MessageBeep MessageBox MessageBoxEx MessageBoxIndirect ModifyMenu mouse_event MoveWindow MsgWaitForMultipleObjects OemKeyScan OemToChar OemToCharBuff OffsetRect OpenClipboard [...]

  2. s.a
    hocam projennin exe halini yayınlayabiirmsn

  3. a.s görüntüdeki exe sadece bu iş için yapılmış bir exe olmadığı için burda yayınlayamam. ilerleyen zamanlarda örnekler atacağım indirebilirsiniz o zaman.

    teşekkürler.

Leave a Reply

(required)

(required)


3 × = six

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

© 2012 Tufan Suffusion theme by Sayontan Sinha