Ir ao conteúdo
  • Cadastre-se

C++ make the mouse move on the ''VK_LBUTTON'' key C++


isvkt

Posts recomendados

my code is simple, it just makes the mouse move down but it moves automatically, i want it to move when i press the ''VK_LBUTTON'' key I tried to put ''if(GetKeyState(VK_LBUTTON)'' but it is closing when I open

 

int main(void)
{
	if (!mouse_open()) {
		printf("[-] failed\n");
		return 0;
	}


	for (int i = 0; i < 32; i++) {
		Sleep(100);
		printf("[+] moving mouse\n");

		mouse_move(0, -10, 0, 0);
	}


	mouse_close();
}

 

  • Confuso 2
Link para o comentário
Compartilhar em outros sites

Hi dear @isvkt

 

I guess you are trying to use Win32, right?

 

Since Win32 is an event driven API, it will tell your program that the left mouse button was pressed with an event signal, witch you need to process with a Win32 event loop

 

Something like this:

#include <windows.h>

  
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR     lpCmdLine,
                   int       nCmdShow)		// This is the "main()" function in win32.
{
	MSG msg;	// Event structure that windows will send to you program (Mouse button down, close, resize etc).

  	// Event loop will send all the messages to a callback function to be processed.
  	while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam; // "main()" returns the event info. 
}


// This is the callback function where you will process the events.
LRESULT CALLBACK WndProc(HWND hWnd,
                          UINT uMsg,
                          WPARAM wParam,
                          LPARAM lParam)
    switch(uMsg)
    {
  	// The event is a mouse left button pressed.
        case WM_LBUTTONDOWN:
        {
        	// Your code to move mouse cursor goes here.
        }
        break;
        
        default:
        // In case of any other event, let Windows process it.
            return (DefWindowProc(hWnd, uMsg, wParam, lParam));
        break;
    }

    return 0;
 }

 

Hope this helps you

  • Curtir 2
Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!