3

Ultimately, I am trying to select a button when there is a left click on the mouse using assembly language but have not found any useful techniques. Any help would be grateful! The code for the program is below.

INCLUDE IRVINE32.inc
INCLUDELIB kernel32.lib
INCLUDELIB user32.lib
INCLUDELIB Winmm.lib
INCLUDELIB Windows.lib
INCLUDELIB kernel32.lib
INCLUDELIB gdi32.lib



WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
ExitProcess PROTO STDCALL :DWORD

WM_LBUTTONDOWN EQU 0x0201

.data
prompt BYTE "Mouse Not Pressed",0
message BYTE "Mouse pressed",0
MouseClick db 0
WM_LBUTTONDOWN bytE 0x0201



.code
main PROC 
mov edx, OFFSET message
.IF WM_LBUTTONDOWN == true
Call WriteString
.ENDIF
mov edx, OFFSET prompt
Call WriteString

invoke ExitProcess, 0
main ENDP
END main

1 Answers1

3

Thanks to MichaelW I could build an example for your needs:

include irvine32.inc

.data

    hStdIn    dd 0
    nRead     dd 0

    _INPUT_RECORD STRUCT
        EventType   WORD ?
        WORD ?                    ; For alignment
        UNION
            KeyEvent              KEY_EVENT_RECORD          <>
            MouseEvent            MOUSE_EVENT_RECORD        <>
            WindowBufferSizeEvent WINDOW_BUFFER_SIZE_RECORD <>
            MenuEvent             MENU_EVENT_RECORD         <>
            FocusEvent            FOCUS_EVENT_RECORD        <>
          ENDS
    _INPUT_RECORD ENDS

    InputRecord _INPUT_RECORD <>

    ConsoleMode dd 0
    Msg db "Click! ",0
    Msg2 db "Esc ",0

.code

main PROC
    invoke GetStdHandle,STD_INPUT_HANDLE
    mov   hStdIn,eax

    invoke GetConsoleMode, hStdIn, ADDR ConsoleMode
    mov eax, 0090h          ; ENABLE_MOUSE_INPUT | DISABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS
    invoke SetConsoleMode, hStdIn, eax

    .WHILE InputRecord.KeyEvent.wVirtualKeyCode != VK_ESCAPE

        invoke ReadConsoleInput,hStdIn,ADDR InputRecord,1,ADDR nRead

        movzx  eax,InputRecord.EventType
        cmp eax, MOUSE_EVENT
        jne no_mouse
        test InputRecord.MouseEvent.dwButtonState, 1
        jz no_mouse

        lea edx, Msg
        Call WriteString
        jmp done

        no_mouse:
    .ENDW

    lea edx, Msg2
    Call WriteString

    done:
    mov eax, ConsoleMode
    invoke SetConsoleMode, hStdIn, eax
    call ReadChar
    invoke ExitProcess, 0
main ENDP

end main
rkhb
  • 14,159
  • 7
  • 32
  • 60
  • Removed my last comment, I thought the alignment issue had been fixed quite some time back. – Michael Petch Nov 28 '15 at 20:42
  • 1
    @MichaelPetch: Do you mean [this one](http://www.masmforum.com/board/index.php?topic=7872)? It seems that it is fixed in masm32v11r/windows.inc as well as in irvine32.inc/smallwin.inc. But the local declaration makes the example more clear :-) – rkhb Nov 28 '15 at 21:37
  • Fair enough. I removed my comment because I realized that it is better safer than sorry since no revision was mentioned. I am your upvoter. – Michael Petch Nov 28 '15 at 21:39
  • @MichaelPetch Thank you for the example. This opens my understanding greatly. – user5577817 Nov 29 '15 at 02:29
  • @user5577817 : I wasn't the kind soul who helped you - rkhb was. If this answer helped you, please consider accepting the answer. More on how to accept and why, please see this SO information: http://meta.stackexchange.com/a/5235/271768 – Michael Petch Nov 29 '15 at 02:57
  • @Michael Petch Thank you! Still new to this website. – user5577817 Nov 29 '15 at 03:11
  • @rkhb Thank you very much !! – user5577817 Nov 29 '15 at 03:11
  • @user5577817 Not a problem and Welcome! – Michael Petch Nov 29 '15 at 03:12