Page 1 of 1

GetNumberOfConsoleInputEvents

PostPosted: 18 May 2013, 21:33
by Steve S
GetNumberOfConsoleInputEvents() for polling does not work in Winboard with FreeBasic or the gcc compiler platform. Are there any code examples of GetNumberOfConsoleInputEvents() for FreeBasic? Here is some basic code that works in console mode, but will not read if called from Winboard:
Code: Select all
#include once "windows.bi"
dim as HANDLE nStdHandle
dim as uinteger lpcNumberOfEvents
dim as integer terminate=0

nStdHandle=GetStdHandle(STD_INPUT_HANDLE)
print "STDIN =";nStdHandle
print "Press any key ..";

do
   sleep 200
   print ".";
   lpcNumberOfEvents=0
   GetNumberOfConsoleInputEvents(nStdHandle, @lpcNumberOfEvents)
   if lpcNumberOfEvents then
   print
   print "lpcNumberOfEvents  ";lpcNumberOfEvents
   terminate=1
   end if
loop until terminate

Re: GetNumberOfConsoleInputEvents

PostPosted: 18 May 2013, 22:15
by H.G.Muller
I am not sure what you are trying to accomplish. You try to run this code aas an engine uner WinBoard? I guess engines do not have a console.

Re: GetNumberOfConsoleInputEvents

PostPosted: 18 May 2013, 22:39
by Steve S
Hello H.G.Muller,
The purpose of using GetNumberOfConsoleInputEvents() is to poll Winboard commands during pondering or analyzing. I assume Winboard sends the commands to STDIN. The above code is an example used in a FreeBasic console. The code would have to be modified to operate under Winboard - for example, output lpcNumberOfEvents to the debug file.

Re: GetNumberOfConsoleInputEvents

PostPosted: 19 May 2013, 16:37
by H.G.Muller
I don't think this will work on Windows. When stdin is a pipe, (as when an engine runs under WinBoard) you will need other calls then when stdin is a keyboard. In my engines I always use PeekNamedPipe() to check for input during pondering. (This of course then doesn't work when you run the engine from the command line, so that stdin is a keyboard.)

Re: GetNumberOfConsoleInputEvents

PostPosted: 19 May 2013, 18:46
by Steve S
This is interesting. The documentation on "Chess Engine Communication Protocol" with Tim Mann suggests to try GetNumberOfConsoleInputEvents() to poll for Input/Output. However, it was not clear that this would not function in windows. PeekNamedPipe() seems to solve the problem (for now).

Re: GetNumberOfConsoleInputEvents

PostPosted: 19 May 2013, 19:09
by H.G.Muller
Well, actually it says this:

CECP specs wrote:Unfortunately, under Win32, the function to use for polling is different depending on whether the input device is a pipe, a console, or something else. (More Microsoft brain damage here -- did they never hear of device independence?) For pipes, you can use PeekNamedPipe to poll (even when the pipe is unnamed). For consoles, you can use GetNumberOfConsoleInputEvents. For sockets only, you can use select().