Recent

Author Topic: ReadKey... as a Word?  (Read 3204 times)

Atreyu

  • Newbie
  • Posts: 1
ReadKey... as a Word?
« on: July 21, 2014, 09:10:23 pm »
Hello Pascal masters...

Long story short, I'm converting a huge legacy application written in TP 5.5 over to FPC. I'm in need of a routine that works exactly like ReadKey in the standard FPC CRT unit, but returns Word instead of Char. If ALT or function keys are pressed, I need the routine to set the "Lo" portion of ReadKeyWord to zero and putting the value in the "Hi" portion.

I'm trying to satisfy the following legacy code from my app:

work:=readkeyword;
if lo(work)=0 then
  begin
    ch:=chr(hi(work));
    if ord(ch) in [16..50] then
      altkv:=ord(ch);
      if (*editmode and *) (ord(ch) in [94..103,104..113]) then
      begin
        if ord(ch) in [94..103] then
          mn:=ord(ch)-83
        else
          mn:=ord(ch)-103;
        current_macro:=macros[mn];
        macro_pos:=1;
        if current_macro<>nil then
          inc:=inc
        else
          inc:=chr(0)
      end
    else
     if ord(ch)<128 then
      inc:=chr(ord(ch)+128)
    else
      inc:=chr(0);
  end
else
  inc:=chr(lo(work));
end

taazz

  • Hero Member
  • *****
  • Posts: 5365
Re: ReadKey... as a Word?
« Reply #1 on: July 21, 2014, 09:16:15 pm »
If I remember correctly readkeyword will convert any pressed key from a byte to a word making sure that if the 1st key read is the extended key the next is placed on the high part of the word in order to avoid running the readkey twice it shouldn't be to hard to duplicate it and no I have no idea if the readkeyword exists in fpc.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Bart

  • Hero Member
  • *****
  • Posts: 4026
    • Bart en Mariska's Webstek
Re: ReadKey... as a Word?
« Reply #2 on: July 21, 2014, 10:25:37 pm »
I used to have a WordKey function in TP way back.
However it was using interrupts to get the key's....
I can try to dig it up if you want to...

You might either take a look at crt unit or kvm (??) unit to see how it polls the OS for keystrokes.

Bart

 

TinyPortal © 2005-2018