News:

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

Main Menu

How to make delay for input after calling ReadConsoleA ?

Started by zin, May 31, 2020, 05:24:03 PM

Previous topic - Next topic

zin

Hello everybody :thumbsup:,
i call to ReadConsoleA for getting input from the console and this run quickly,
how can i make  delay that my console let me input some charcters?
there is build windwos api function for this? or i make this with some loop?

Vortex

Hi zin,

The trick is to set the set correct console mode :

https://docs.microsoft.com/en-us/windows/console/setconsolemode

The example below is based on the masm32 library function StdIn :

\masm32\m32lib\stdin.asm

The line :

;   invoke ReadFile,hInput,lpszBuffer,bLen,ADDR bRead,NULL

is replaced by this one :

    invoke ReadConsole,hInput,lpszBuffer,bLen,ADDR bRead,NULL

include     \masm32\include\masm32rt.inc

StdInput    PROTO :DWORD,:DWORD

BUFFER_SIZE equ 512

.data?

buffer      db BUFFER_SIZE dup(?)

.code

start:

    invoke  StdInput,ADDR buffer,BUFFER_SIZE

    invoke  StdOut,ADDR buffer

    invoke  ExitProcess,0

StdInput PROC lpszBuffer:DWORD,bLen:DWORD

    LOCAL hInput :DWORD
    LOCAL bRead  :DWORD

    invoke GetStdHandle,STD_INPUT_HANDLE
    mov hInput, eax

    invoke SetConsoleMode,hInput,ENABLE_LINE_INPUT or \
                                 ENABLE_ECHO_INPUT or \
                                 ENABLE_PROCESSED_INPUT

;   invoke ReadFile,hInput,lpszBuffer,bLen,ADDR bRead,NULL

    invoke ReadConsole,hInput,lpszBuffer,bLen,ADDR bRead,NULL

  ; -------------------------------
  ; strip the CR LF from the result
  ; -------------------------------
    mov edx, lpszBuffer
    sub edx, 1
  @@:
    add edx, 1
    cmp BYTE PTR [edx], 0
    je @F
    cmp BYTE PTR [edx], 13
    jne @B
    mov BYTE PTR [edx], 0
  @@:

    mov eax, bRead
    sub eax, 2

    ret

StdInput ENDP

END start


zin

hello Vortex,
Thenk you for the invested respond !!
:thumbsup: