Re: Win32 non blocking console input?



On Oct 15, 5:04 am, Herbert Kleebauer <k...@xxxxxxxxx> wrote:
NathanCBa...@xxxxxxxxx wrote:
On Oct 14, 4:51 am, Herbert Kleebauer <k...@xxxxxxxxx> wrote:
Here it is in your favorite syntax:

I can live with the syntax, but does this work for you? Even if I

Why not just use a pop-up window??

A pop-up window in batch program? Seems the point-and-click generation
hasn't respect for anything! But how should this help, don't think
that MessageBox() has a time-out parameter.

Here you go:

program TimeGetc;
#include( "w.hhf" )
#include( "stdlib.hhf" )

static
hInstance: dword;
key: dword;

readonly

ClassName: string := "TimeGetcClass";
AppName: string := "Press a key!";

var
wc: w.WNDCLASSEX;
hwnd: dword;

procedure WndProc( hWnd:dword; uMsg:uns32; wParam:dword;
lParam:dword ); @stdcall;

begin WndProc;

if( uMsg = w.WM_DESTROY ) then

w.PostQuitMessage( 0 );
sub( eax, eax );

elseif( uMsg = w.WM_CREATE ) then

w.SetTimer( hWnd, 500, 3000, NULL );

elseif( uMsg = w.WM_TIMER ) then

w.KillTimer( hWnd, 500 );
w.SendMessage( hWnd, w.WM_DESTROY, 0, 0 );
mov( 0, key );

elseif( uMsg = w.WM_KEYDOWN ) then

w.KillTimer( hWnd, 500 );
w.SendMessage( hWnd, w.WM_DESTROY, 0, 0 );
mov( 1, key );

else

w.DefWindowProc( hWnd, uMsg, wParam, lParam );

endif;

end WndProc;

procedure QuickGet( window:dword );

var
msg: w.MSG;

begin QuickGet;

forever

w.GetMessage( msg, NULL, 0, 0 );
breakif( !eax );
w.TranslateMessage( msg );
w.DispatchMessage( msg );

endfor;
mov( msg.wParam, eax );

end QuickGet;

begin TimeGetc;

w.GetModuleHandle( NULL );
mov( eax, hInstance );

mov( @size( w.WNDCLASSEX ), wc.cbSize );
mov( w.CS_HREDRAW | w.CS_VREDRAW, wc.style );
mov( &WndProc, wc.lpfnWndProc );
mov( 0, wc.cbClsExtra );
mov( 0, wc.cbWndExtra );

mov( hInstance, wc.hInstance );
mov( w.COLOR_WINDOW+1, wc.hbrBackground );
mov( NULL, wc.lpszMenuName );
mov( ClassName, wc.lpszClassName );

w.LoadIcon( NULL, val w.IDI_APPLICATION );
mov( eax, wc.hIcon );
mov( eax, wc.hIconSm );

w.LoadCursor( NULL, val w.IDC_ARROW );
mov( eax, wc.hCursor );

w.RegisterClassEx( wc );
w.CreateWindowEx
(
0,
ClassName,
AppName,
w.WS_OVERLAPPED,
200,
200,
200,
200,
0,
0,
hInstance,
NULL
);
mov( eax, hwnd );

w.ShowWindow( hwnd, w.SW_SHOWDEFAULT );
w.UpdateWindow( hwnd );

// Ask the user to press a key within 3 seconds.

QuickGet( hwnd );

mov( key, eax );
if ( eax == 1 ) then
stdout.put( "A key was pressed!", nl );
else
stdout.put( "The event timed out!", nl );
endif;

// Give the user a second chance to press a key.

w.ShowWindow( hwnd, w.SW_SHOWDEFAULT );
w.UpdateWindow( hwnd );
w.SendMessage( hwnd, w.WM_CREATE, 0, 0 );

QuickGet( hwnd );

mov( key, eax );
if ( eax == 1 ) then
stdout.put( "A key was pressed!", nl );
else
stdout.put( "The event timed out!", nl );
endif;

end TimeGetc;

Nathan.
.



Relevant Pages

  • Re: RDTSC instruction question on core 2 duo CPU
    ... then prints the 'GetThreadTimes' results to a console window. ... mov(eax, hThread); ... w.KillTimer(hWnd, 500); ...
    (alt.lang.asm)
  • Re: Macro2D
    ... õ1, eax", 0 ... db "push striIIi", NL ... db ".2: cmp edi, ebp", NL ... db ".4: mov eax, edi", NL ...
    (alt.lang.asm)
  • One RosAsm Pre-parser
    ... cmp eax 0 | ja L0<< ... mov ecx, D ...
    (alt.lang.asm)
  • Re: Fastcode Library Design
    ... cmp ecx, SMALLMOVESIZE ... lea edx, ... fild qword ptr [eax] ... mov ecx, ...
    (borland.public.delphi.language.basm)
  • Re: Macro2D
    ... mov, eax ... cmp eax, -1 ... push STD_INPUT_HANDLE ...
    (alt.lang.asm)

Loading