flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > A Win32 console keypress example (Updated)

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20062
Location: In your JS exploiting you and your system
revolution 02 Apr 2024, 11:04
This might help.
Code:
struc   COORD {
        .x      dw      ?
        .y      dw      ?
}struct COORD

struc   UCHAR {
    virtual
        .AsciiChar      db      ?
    end virtual
        .UnicodeChar    dw      ?
}struct UCHAR

struc   KEY_EVENT_RECORD {
        .bKeyDown               dd      ?
        .wRepeatCount           dw      ?
        .wVirtualKeyCode        dw      ?
        .wVirtualScanCode       dw      ?
        .uChar                  UCHAR
        .dwControlKeyState      dd      ?
}struct KEY_EVENT_RECORD

struc   MOUSE_EVENT_RECORD {
        .dwMousePosition        COORD
        .dwButtonState          dd      ?
        .dwControlKeyState      dd      ?
        .dwEventFlags           dd      ?
}struct MOUSE_EVENT_RECORD

struc   WINDOW_BUFFER_SIZE_RECORD {
        .dwSize COORD
}struct WINDOW_BUFFER_SIZE_RECORD

struc   MENU_EVENT_RECORD {
        .dwCommandId    dd      ?
}struct MENU_EVENT_RECORD

struc   FOCUS_EVENT_RECORD {
        .bSetFocus      dd      ?
}struct FOCUS_EVENT_RECORD

struc   IREVENT {
    virtual
        .MouseEvent             MOUSE_EVENT_RECORD
        .WindowBufferSizeEvent  WINDOW_BUFFER_SIZE_RECORD
        .MenuEvent              MENU_EVENT_RECORD
        .FocusEvent             FOCUS_EVENT_RECORD
    end virtual
        .KeyEvent               KEY_EVENT_RECORD
}struct IREVENT

struc   INPUT_RECORD {
        .EventType      dw      ?,?
        .Event          IREVENT
}struct INPUT_RECORD    
Post 02 Apr 2024, 11:04
View user's profile Send private message Visit poster's website Reply with quote
MatQuasar



Joined: 25 Oct 2023
Posts: 68
MatQuasar 02 Apr 2024, 16:28
revolution wrote:
This might help.
Code:
struc   COORD {
        .x      dw      ?
        .y      dw      ?
}struct COORD

struc   UCHAR {
    virtual
        .AsciiChar      db      ?
    end virtual
        .UnicodeChar    dw      ?
}struct UCHAR

struc   KEY_EVENT_RECORD {
        .bKeyDown               dd      ?
        .wRepeatCount           dw      ?
        .wVirtualKeyCode        dw      ?
        .wVirtualScanCode       dw      ?
        .uChar                  UCHAR
        .dwControlKeyState      dd      ?
}struct KEY_EVENT_RECORD

struc   MOUSE_EVENT_RECORD {
        .dwMousePosition        COORD
        .dwButtonState          dd      ?
        .dwControlKeyState      dd      ?
        .dwEventFlags           dd      ?
}struct MOUSE_EVENT_RECORD

struc   WINDOW_BUFFER_SIZE_RECORD {
        .dwSize COORD
}struct WINDOW_BUFFER_SIZE_RECORD

struc   MENU_EVENT_RECORD {
        .dwCommandId    dd      ?
}struct MENU_EVENT_RECORD

struc   FOCUS_EVENT_RECORD {
        .bSetFocus      dd      ?
}struct FOCUS_EVENT_RECORD

struc   IREVENT {
    virtual
        .MouseEvent             MOUSE_EVENT_RECORD
        .WindowBufferSizeEvent  WINDOW_BUFFER_SIZE_RECORD
        .MenuEvent              MENU_EVENT_RECORD
        .FocusEvent             FOCUS_EVENT_RECORD
    end virtual
        .KeyEvent               KEY_EVENT_RECORD
}struct IREVENT

struc   INPUT_RECORD {
        .EventType      dw      ?,?
        .Event          IREVENT
}struct INPUT_RECORD    


Good!
Post 02 Apr 2024, 16:28
View user's profile Send private message Reply with quote
MatQuasar



Joined: 25 Oct 2023
Posts: 68
MatQuasar 13 Apr 2024, 15:25
Another example modified from code posted by a 'fasm' Discord user.

GetKeyState API function : "Press "0" to quit"

Code:
format PE console
include 'win32a.inc'

msg db 'Key pressed',13,10
len = $ - msg
msgg db 'Press 0 to quit',13,10
lenn = $ - msgg
stdout dd ?

entry $

  invoke GetStdHandle,STD_OUTPUT_HANDLE
  mov [stdout],eax

  invoke WriteConsole,[stdout], msgg, lenn, 0, 0
  mov ebx, '0'

.again:
  invoke GetKeyState,ebx

  bt eax,15
  jnc .again

  invoke WriteConsole,[stdout], msg, len, 0, 0
  invoke ExitProcess,0

data import
library kernel,'kernel32.dll',user32,'user32.dll'
import  kernel, WriteConsole,'WriteConsoleA',GetStdHandle,'GetStdHandle', ExitProcess, 'ExitProcess'
import  user32, GetKeyState,'GetKeyState',GetAsyncKeyState,'GetAsyncKeyState'
end data

    
Post 13 Apr 2024, 15:25
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.