Page 1 of 1

keyboard clear buffer

PostPosted: Thu Feb 01, 2018 11:09 am
by ukoenig
Hello

viewtopic.php?f=3&t=33093&p=194872&hilit=keyboard+clear#p194872

to break a combination of < DO WHILE > and < FOR NEXT > with < RETURN > I'm using

IF LASTKEY() = 13
IF MsgYesNo("Exit from topic collect ?", "EXIT" )
nPage := nPages + 10 // < do while > break
lBreak := .T. // < for next > break
ENDIF
ENDIF


at the end I call -> CLEARKEYBOARD()

the break only works once because the keybord-buffer still shows 13

At the end of the function I test with

MsgAlert( LASTKEY(), "Lastkey" ) still shows 13

any idea :?:

Code: Select all  Expand view

#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

HB_FUNC( CLEARKEYBOARD )
{
MSG stMsg = { 0 };

HWND hWnd = ( HWND ) hb_parnl( 1 );

while( PeekMessage( &stMsg, hWnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE ) );

hb_ret();
}

#pragma ENDDUMP
 


regards
Uwe :(

Re: keyboard clear buffer

PostPosted: Thu Feb 01, 2018 3:38 pm
by Antonio Linares
Uwe,

Try it this way
Code: Select all  Expand view
while( PeekMessage( &stMsg, hWnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE ) )
{
   TranslateMessage( &stMsg );        
   DispatchMessage( &stMsg );  
}
 

Re: keyboard clear buffer

PostPosted: Thu Feb 01, 2018 5:00 pm
by ukoenig
Antonio,

lastkey() still shows 13

instead of clear I found another solution
for the break and added

__keyboard( "A" ) // 65
lastkey() = 65

Code: Select all  Expand view

...
...
        IF LASTKEY() = 13
             IF MsgYesNo("Exit from topic collect ?", "EXIT" )
                  nPage := nPages + 10 // forces the exit from DO WHILE
                  lBreak := .T. // forces the exit from FOR NEXT
                  __keyboard( "A" )
             ENDIF
       ENDIF
       nPage++
       IF nPage > nPages
            EXIT
       ENDIF
   ENDDO
   IF lBreak = .T.
       EXIT
    ENDIF
NEXT nTopic

 


regards
Uwe :D