Jump to content
paulsk8

Sendmessage putin ajutor

Recommended Posts

Salut

Am niste probleme cu sendmessage..doresc de exemplu sa trimit butonul ESC la programul principal.

Declar sendmessage-ul

private const int HWND_BROADCAST = 0xffff;

[DllImport("user32.dll")]

public static extern int SendMessage(

int hWnd, // unde se trimite

uint Msg, // ce se trimite

long wParam, // parametru ..

long lParam // parametru

);

uint VK_ESCAPE = 0x1B; // esc

Daca dau

SendMessage(HWND_BROADCAST, VK_ESCAPE, 0, 0);

imi da eroare..

ce am gresit? parametrii ?

Link to comment
Share on other sites

Nu obligatoriu la cel principal..

keybd am incercat dar nu merge in jocuri ( ceea ce incerc eu )

As dori la procesul gta_sa, dar nu mi-am dat seama cum...

Cat despre sendinput nu am inteles absolut deloc care e treaba cu el..

Cum pot face sa trimit niste taste unui proces ales de mine? hwnd=Procces("notepad.exe") ?

Edited by paulsk8
Link to comment
Share on other sites

E cam aiurea daca vrei sa gasesti fereastra in functie de proces.

Poti face asta: folosesti EnumWindows function (Windows) pentru a gasi toate ferestrele, ce necesita crearea unei functii callback EnumWindowsProc callback function (Windows) si pentru fiecare fereastra cauti process ID-ul cu GetWindowThreadProcessId function (Windows) , pe acesta fiind usor sa il afli GetProcessId function .

Dar NU se procedeaza asa.

Trebuie sa gasesti direct fereastra cu functiile FindWindow function si FindWindowEx function . Foloseste un program ca Spy++ sau WinspectorSpy pentru a descoperi clasele si numele/titlurile ferestrelor (proprietati ale ferestrelor dupa care poti face cautarea cu aceste functii) si astfel vei avea handler-ul ferestrei.

Apoi vei putea folosi SendMessage pentru a trimite KEYDOWN/UP:

SendMessage(hWnd, WM_KEYDOWN, buton, 0);

SendMessage(hWnd, WM_KEYUP, buton, 0);

Cu keybd_event function sau SendInput function e mai simplu in sensul ca nu ai nevoie de nicio fereastra, functiile pur si simplu simuleaza apasarea unor taste, mesajele acestea ajungand la fereastra activa. Adica pui codul sa apeleze in timp ce te afli in joc, poti cauta intr-un Timer/cu un Sleep() fereastra de joc cu GetForegroundWindow function .

Folosirea lui SendInput function poate fi putin greoaie, dar e foarte practica functia. Uite aici un exemplu de folosire: Google Answers: Using SendInput to send a number

Ai grija cu C#-ul, e posibil sa ai foarte multe probleme, cu Pointeri sau dimensiunea parametrilor cu care apelezi functiile API, e posibil sa trebuiasca sa folosesti functiile din clasa Marshal Class (System.Runtime.InteropServices) .

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...