Results 1 to 6 of 6
  1. #1
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed

    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

  2. #2
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    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.

  3. #3
    HackShield69's Avatar
    Join Date
    Jul 2011
    Gender
    female
    Posts
    6
    Reputation
    10
    Thanks
    1
    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

  4. The Following User Says Thank You to HackShield69 For This Useful Post:

    258456 (07-13-2011)

  5. #4
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    Well, it works fine like this so it will do, but thanks for the suggestion

  6. #5
    kibbles18's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Location
    US
    Posts
    860
    Reputation
    5
    Thanks
    127
    aha lol. i didnt notice that it was getkeystate, i assumed it said getasynckeystate. i never even knew getkeystate existed o.0

  7. #6
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    ya same here. haha

Similar Threads

  1. [Help] How i can play games with a controller at same time with a keyboard/mouse?
    By MyGameNoob in forum Emulator & Rom Hacking
    Replies: 4
    Last Post: 07-03-2011, 01:23 PM
  2. XIM3 - pc like mouse control for xbox360
    By NotHuman in forum XBOX General Discussion
    Replies: 10
    Last Post: 02-08-2011, 07:58 PM
  3. Game Controllers vs. Keyboard+Mouse
    By blueduece2 in forum General
    Replies: 1
    Last Post: 02-10-2009, 08:43 AM
  4. ASM Tutorial Link
    By SpiderByte in forum Assembly
    Replies: 4
    Last Post: 08-19-2008, 12:35 PM
  5. CBS Controls StarTrek
    By Dave84311 in forum SCI-FI
    Replies: 5
    Last Post: 01-22-2006, 11:18 PM