Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Accessing Int 33h

Started by srfpala, November 09, 2013, 04:04:26 AM

Previous topic - Next topic


I'm using

INCLUDELIB \masm32\lib\Irvine32.lib
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib

WinASM reports

Clean assemble
Clean link
and Program runs fine.

I add
  mov   ax,1
  int   33h

Program aborts on int 33h  command.

Why ?
What am I missing?


the INTerrupt mechanism is for 16-bit programs
for 32-bit programs, things are very different
if you have a window, the WndProc routine receives mouse messages
for console-mode programs, you receive mouse inputs in the same buffer as the keyboard
there are also a few functions, like GetCursorPos that work asynchronously

decide whether you want a 16-bit or 32-bit program, then proceed from there


Hey dedndave, could you go into detail about console mode programs and how the mouse input buffer would work? Or could you provide some sort of sources I could look at to find this information? I've been looking for the last 2 hours about how to do mouse input for console mode and I can't find anything helpful, it took me forever to find this thread to start with.


asynchronously, you can always get the mouse position with GetCursorPos

however, you can also perceive mouse actions by examining the input buffer
in this code, i use the same method to look for keys

AnyKey  PROC

;UNICODE Aware Wait for Any Console Key Press - DednDave
;version 1, 12-2011
;version 2, 2-2013
;  This function returns when any console key is pressed (bKeyDown = 1).
;The function does not return for Shift/Alt/Ctrl keypresses.
;A possible drawback is that all input event records (mouse etc) are removed
;from the console input queue until a key is pressed. In many cases, this is
;not an issue. The virtual key code, virtual scan code, TCHAR character,
;and control key state values are returned in registers.

;Call With: Nothing
;  Returns: EAX = TCHAR character (high word of EAX = 0)
;           ECX = control key state flags
;               Bit   Name                Meaning
;                0    RIGHT_ALT_PRESSED   Right ALT key is pressed
;                1    LEFT_ALT_PRESSED    Left ALT key is pressed
;                2    RIGHT_CTRL_PRESSED  Right CTRL key is pressed
;                3    LEFT_CTRL_PRESSED   Left CTRL key is pressed
;                4    SHIFT_PRESSED       SHIFT key is pressed
;                5    NUMLOCK_ON          NUM LOCK light is on
;                6    SCROLLLOCK_ON       SCROLL LOCK light is on
;                7    CAPSLOCK_ON         CAPS LOCK light is on
;                8    ENHANCED_KEY        Key is enhanced
;           EDX: high word = virtual scan code
;            low word (DX) = virtual key code
;Also Uses: EBX, ESI, EDI, EBP are preserved


    LOCAL   ir          :INPUT_RECORD
    LOCAL   uRecCnt     :UINT
    LOCAL   hStdInp     :HANDLE


    mov     hStdInp,eax
        INVOKE  ReadConsoleInput,hStdInp,addr ir,1,addr uRecCnt
        movzx   ecx,word ptr ir.EventType
        mov     edx,dword ptr ir.KeyEvent.wVirtualKeyCode
    .until (ecx==KEY_EVENT) && (ecx==ir.KeyEvent.bKeyDown) && (dx!=VK_SHIFT) && (dx!=VK_CONTROL) && (dx!=VK_MENU)
    movzx   eax,word ptr ir.KeyEvent.UnicodeChar
    mov     ecx,ir.KeyEvent.dwControlKeyState

AnyKey  ENDP


notice that it looks for KEY_EVENT's
the INPUT_RECORD structure may also contain MOUSE_EVENT's

i have never used it that way - i usually skip over mouse events - lol
but, it shouldn't be hard to figure out with the documentation
you may also want to use Get/SetConsoleMode

you may want to get the current console mode, store it
then set the mode - read inputs
then set the mode back to the original state before exit


personally, if i want to use the mouse - i would write a GUI app   :t

EDIT: give me a few minutes to clean up a little example.....


Here is a low tech example. The way to go is, as Dave rightly stated, ReadConsoleInput.

include \masm32\MasmBasic\        ; download
  Print "Hold the left mousekey down and move the mouse - hit Escape to quit"
        invoke Sleep, 1
        invoke GetKeyState, VK_LBUTTON        ; kind of undocumented but it works ;-)
        .if sbyte ptr ah<0
                imul edi, MouseX, 85        ; may need adjustment for different screen resolutions or console fonts
                sar edi, 10
                imul ecx, MouseY, 50        ; may need adjustment
                sar ecx, 10
                Locate(edi, ecx)
                Print "."        ; show the point
        invoke GetKeyState, VK_ESCAPE
  .Until sbyte ptr ah<0
end start


GUI example - the mouse position is in the status bar

you can also handle WM_LBUTTONDOWN and WM_RBUTTONDOWN messages to get clicks

EDIT: removed attachment, see next post


i cleaned up my status bar/mouse example a little bit
fixed a couple things...