Re: 3.0.3 Release Candidate for Windows/DOS

new topic     » goto parent     » topic index » view thread      » older message » newer message

I Juergen,
Strangely I don't get the same result as you. I translated key.ex with euphoria
3.0.2 and Borland compiler and contrary to you I don't get the ESC and function
keys.
Its not really a surprise to me because When using borland or LCC, the backend
use win32api function ReadConsole()
and before calling wingetch() get_key() SetConsoleMode with
ENABLE_PROCESSED_INPUT flag.
The order of call is:
get_key() SetConsoleMode and call wingetch() //in file be_runtime.c
wingetch() call MyReadConsoleChar()
MyReadConsoleChar() call win32api ReadConsole() //in file be_w.c

The problem here is that when the input console buffer is set with the flag
ENABLE_PROCESSED_INPUT
the function keys are processed by the system and not sent to the console input
buffer.
In fact I tested SetConsoleMode(hStdin, 0) and ReadConsole() doesn't return the
function key neither.

-- test code for the Readconsole() behavior
include dll.e
include machine.e

constant kernel32 = open_dll("kernel32.dll")

constant iGetStdHandle = define_c_func(kernel32,"GetStdHandle",{C_UINT},C_UINT)
constant iReadConsole =
define_c_func(kernel32,"ReadConsoleA",{C_POINTER,C_POINTER,C_UINT,C_POINTER,C_POINTER},C_UINT)
constant iSetConsoleMode =
define_c_proc(kernel32,"SetConsoleMode",{C_POINTER,C_UINT})

constant STD_INPUT_HANDLE = -10,  STD_OUTPUT_HANDLE = -11, STD_ERROR_HANDLE =
-12, ENABLE_PROCESSED_INPUT = 1

atom hstdin

  
function MyReadConsoleChar()
object fnVal
atom pBuffer,pNbrRead

  pBuffer = allocate(4)
  pNbrRead = allocate(4)
fnVal =
  c_func(iReadConsole,{hstdin,pBuffer,1,pNbrRead,ENABLE_PROCESSED_INPUT})
  fnVal = peek(pBuffer)
  free(pNbrRead)
  return fnVal  
end function

function wingetch()
integer c
  c=MyReadConsoleChar()
  if c = 0 then return -1 end if
  if c = '\r' then
  --  c = MyReadConsoleChar()
  end if
  return c
end function

integer code

puts(1, "Press any key. I'll show you the key code. Press q to quit\n\n")
hstdin = c_func(iGetStdHandle,{STD_INPUT_HANDLE})
c_proc(iSetConsoleMode,{hstdin,ENABLE_PROCESSED_INPUT})

while 1 do
    code = wingetch() --get_key()
    if code != -1 then
    printf(1, "The key code is: %d\n", code)
    if code = 'q' then
        exit
    end if
    end if
end while



CONCLUSION: my bug fix in MyReadConsoleChar() as nothing to  see with this other
bug.

Regards,
Jacques DeschĂȘnes

Juergen Luethje wrote:
> I don't have LCC, but at least for Borland there was exactly the same bug 
> with wait_key(), which is also "fixed" now. I think this should be documented
> in the release notes, too.
> 
> I wrote "fixed" in quotes, because the bug fix introduced a new issue:
> I translated Euphoria's 'key.ex' with Eu 3.0.2 and Eu 3.0.3, respectively,
> and compiled with Borland.
> 'key.exe' translatd with Eu 3.0.2 shows e.g. the codes for [ESC] and for
> function keys, as expected. 'key.exe' translatd with Eu 3.0.3 does not do
> so. IMHO this is a bigger disadvantage than the required extra keystroke
> after a carriage return.
> 
> Regards,
>    Juergen

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu