Control Mouse ASM

Posts 1–6 of 6 · Page 1 of 1
Control Mouse ASM
Ok so I made a program that makes it possible to control your mouse from your keyboard (why? cuz i am practicing asm). It works by checking for keystrokes but the problem is when i press any hotkey. The hotkey works but when i lift my finger it still goes even though the key isn't activated. Here's my code, it looks long but it's actually all tedious:

Code:
.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib


.data
x dd 0
y dd 500
click dd 0
p POINT <>


.code
start:

mov eax, 0
mov ecx, 0
jmp mouse


mouse:

push VK_RIGHT
call GetKeyState

cmp eax, 1
je move_right

push VK_UP
call GetKeyState

cmp eax, 1
je mouse_up

push VK_DOWN
call GetKeyState

cmp eax, 1
je mouse_down

push VK_LEFT
call GetKeyState

cmp eax, 1
je mouse_left

push VK_RETURN
call GetKeyState

mov click, eax
cmp click, 0
je mouse_click

jmp mouse

mouse_down:

push offset p
call GetCursorPos

add p.y, 5
mov eax, p.y
mov ecx, p.x

push eax
push ecx
call SetCursorPos

push 1
call Sleep

jmp mouse

move_right:

push offset p
call GetCursorPos

add p.x, 5
mov eax, p.y
mov ecx, p.x

push eax
push ecx
call SetCursorPos

push 1
call Sleep

jmp mouse

mouse_left:

push offset p
call GetCursorPos

sub p.x, 5
mov eax, p.y
mov ecx, p.x

push eax
push ecx
call SetCursorPos

push 1
call Sleep

jmp mouse


mouse_up:

push offset p
call GetCursorPos

sub p.y, 5
mov eax, p.y
mov ecx, p.x

push eax
push ecx
call SetCursorPos

push 1
call Sleep

jmp mouse

mouse_click:
push 0
push 0
push 0
push 0
push MOUSEEVENTF_LEFTDOWN
call mouse_event

push 5 
call Sleep

push 0
push 0
push 0
push 0
push MOUSEEVENTF_LEFTUP
call mouse_event
mov click, 1
jmp mouse

end start
ok, i solved it. Instead of GetKeyState, just use GetAsyncKeyState. GetKeyState is a good key for hacks though, it's better than using a bool cause you can use the return value directly since it works by a button getting toggled not seeing if the button is actually down.
Quote Originally Posted by 258456 View Post
ok, i solved it. Instead of GetKeyState, just use GetAsyncKeyState. GetKeyState is a good key for hacks though, it's better than using a bool cause you can use the return value directly since it works by a button getting toggled not seeing if the button is actually down.
you also can't use GetKeyState since you need a message pump on the thread you're calling it from
Well, it works fine like this so it will do, but thanks for the suggestion
aha lol. i didnt notice that it was getkeystate, i assumed it said getasynckeystate. i never even knew getkeystate existed o.0
ya same here. haha
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us