News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Pause function

Started by MaynardG_Krebs, March 03, 2007, 06:31:21 PM

Previous topic - Next topic

MichaelW

Quote from: Ehtyar on March 04, 2007, 03:40:59 AM
(and why is a loop required if you're not using the return value anyway?)
The loop waits for a key press, with essentially a CPU utilization of zero. The call to crt__getch removes the keystroke from the buffer, leaving it empty, and returns the key character.

To me, "nasty hack" describes code that is ill designed and unreliable. The wait_key procedure is neither.
eschew obfuscation

MaynardG_Krebs

Thanks to everyone for the input and great code samples! This gives me a lot of information to digest and more code to play around with. :P
I can see advantages in each, ranging from simplicity to functionality.

GregL

Well, I don't "desperately want" the extra functionality but there are times when it's the best option.

I prefer to use the Windows API, but there are times when recreating the functionality of a C Run-Time function is not worth it. The CRT functions work and have been exhaustively tested over the years. If you are looking for maximum speed, you probably don't want to use a CRT function. If you are looking for reliability and stability and the Windows API doesn't offer the functionality you need, they are a good way to go.

I know I will never convince the "purists" around here.  If you don't want to use the CRT functions, fine, don't use them, but criticizing people for using them is out of line.



PBrennick

Greg,
Very well said.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

sinsi

OK, maybe I didn't have enough beers  :(

WaitForKey PROC uses edi
    invoke GetStdHandle,STD_INPUT_HANDLE
    mov edi,eax
    invoke FlushConsoleInputBuffer,edi         ;make sure there are no keystrokes
    invoke WaitForSingleObject,edi,INFINITE    ;wait for a key down
    invoke FlushConsoleInputBuffer,edi         ;remove the keydown so it doesn't echo
    invoke WaitForSingleObject,edi,INFINITE    ;wait for a key up
    invoke FlushConsoleInputBuffer,edi         ;remove the keyup so it doesn't echo
    ret
WaitForKey ENDP

Now it's getting a bit too complicated (and maybe a bit too long time-wise?).
And there is the problem of a key held down and repeating...

I must admit I don't use CRT at all - it seems a bit much to load a big DLL just to use one function - but that is my personal preference.
Why isn't there a PressAnyKey function in kernel32 boo hoo.
Light travels faster than sound, that's why some people seem bright until you hear them.

Mark Jones

The above un-pauses when I mouse-over the CUI window. :lol

I had to add:


invoke SetConsoleMode,hConsoleInput,ENABLE_LINE_INPUT or \
    ENABLE_ECHO_INPUT or \
    ENABLE_PROCESSED_INPUT
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08