On Fri, 04 Jul 2008 12:01:39 +0200, Mario Donick <mario.don...@gmail.com> wrote: > Hello,
> this is a question for people who know FreePascal.
> I'm using the unit "keyboard" to process console input:
> I wait for a keyevent with GetKeyEvent. Afterwards, I process it with > TranslateKeyEvent and KeyEventToString, for example:
[snip example]
No point in using KeyEventToString to identify keys. It creates overhead. GetKeyEventCode is all you need. Here is an excerpt from Valkyrie library vinput.pas unit, function TTextModeInput.GetVCode:
var ch : char; Key : TKeyEvent; begin Key:=GetKeyEvent; Key:=TranslateKeyEvent(Key); ... case GetKeyEventCode(Key) of InputKeyEscape : Exit(VKEY_ESCAPE); ... kbdUp : Exit(VKEY_UP); kbdDown : Exit(VKEY_DOWN); kbdLeft : Exit(VKEY_LEFT); kbdRight : Exit(VKEY_RIGHT); ...
Plus some constants: const InputKeyBackSpace = $0E08; InputKeyEnter = $1C0D; InputKeyTab = $0F09; InputKeyEscape = $011B;
Note that under Unix escape still needs to be pressed twice to be read. -- Michal Bielinski
Am Fri, 04 Jul 2008 16:56:15 +0200 schrieb Michal Bielinski:
> On Fri, 04 Jul 2008 12:01:39 +0200, Mario Donick > <mario.don...@gmail.com> wrote: >> I wait for a keyevent with GetKeyEvent. Afterwards, I process it with >> TranslateKeyEvent and KeyEventToString, for example:
> No point in using KeyEventToString to identify keys. It creates > overhead. GetKeyEventCode is all you need.
Hmmm, okay. I will try to rewrite my input routines that way.
> Note that under Unix escape still needs to be pressed twice to be read.
Is this intended or a bug? If intended: by Linux or by FreePascal? Is there a way to deal with this, except telling the player that he has to press ESC twice?
I already see the complaints of Krice (although he might not use Unix): "Why do I have to press ESC twice? Are you retarded?" ;-)
On Fri, 04 Jul 2008 17:36:44 +0200, Mario Donick <mario.don...@gmail.com> wrote: > Am Fri, 04 Jul 2008 16:56:15 +0200 schrieb Michal Bielinski: >> No point in using KeyEventToString to identify keys. It creates >> overhead. GetKeyEventCode is all you need.
> Hmmm, okay. I will try to rewrite my input routines that way.
Valkyrie library is LGPL if you would like to use it. Saves development time although it isn't without its own problems.
>> Note that under Unix escape still needs to be pressed twice to be read.
> Is this intended or a bug? If intended: by Linux or by FreePascal? Is > there a way to deal with this, except telling the player that he has to > press ESC twice?
Short summary: Intended, by Linux, get a barebone console. IIRC this is why ADoM employed z as exit key.
Am Fri, 04 Jul 2008 20:27:05 +0200 schrieb Michal Bielinski:
> On Fri, 04 Jul 2008 17:36:44 +0200, Mario Donick > <mario.don...@gmail.com> wrote: >> Am Fri, 04 Jul 2008 16:56:15 +0200 schrieb Michal Bielinski: > Valkyrie library is LGPL if you would like to use it. Saves development > time although it isn't without its own problems.
Yeah, I really like Valkyrie, but I recognized its existence too late. Using it for LambdaRogue now would require me to rewrite nearly everything. However, I PLAN to rewrite the game someday (after release 1.0 and several updates of the 1.0 branch), to make it object oriented etc. Then I'll consider using Valkyrie.
By the way, I only needed to add one simple if clause to make ESC working.
>>> Note that under Unix escape still needs to be pressed twice to be >>> read.
>> Is this intended or a bug? If intended: by Linux or by FreePascal? Is >> there a way to deal with this, except telling the player that he has to >> press ESC twice?
> Short summary: > Intended, by Linux, get a barebone console. IIRC this is why ADoM > employed z as exit key.
In a state of madness Michal Bielinski wrote the following :
> On Fri, 04 Jul 2008 17:36:44 +0200, Mario Donick <mario.don...@gmail.com> wrote: >> Am Fri, 04 Jul 2008 16:56:15 +0200 schrieb Michal Bielinski: >>> No point in using KeyEventToString to identify keys. It creates >>> overhead. GetKeyEventCode is all you need. >> Hmmm, okay. I will try to rewrite my input routines that way.
> Valkyrie library is LGPL if you would like to use it. Saves development time > although it isn't without its own problems.
BSD or MIT if anyone asks for permission ;).
What problems? I'll gladly address them when I have time.
On Mon, 07 Jul 2008 02:35:49 +0200, Kornel Kisielewicz <admin@nospam_chaosforge.org> wrote: > In a state of madness Michal Bielinski wrote the following : >> Valkyrie library is LGPL if you would like to use it. Saves development time >> although it isn't without its own problems.
> BSD or MIT if anyone asks for permission ;).
> What problems? I'll gladly address them when I have time.
First, sorry for delayed reply. That means you did not receive my email. I sent it again to adminATchaosfogeDOTorg. Have a look, I described a way to make sure that terminals are not left crippled after program using Valkyrie TextOutput finishes. -- Michal Bielinski
On Wed, 09 Jul 2008 21:29:45 +0200, Mario Donick <mario.don...@gmail.com> wrote: > Am Wed, 09 Jul 2008 11:09:06 -0700 schrieb Krice: >> If Esc is reserved in unix then it could be wiser to use another key >> like 'x' or whatever, or make them both work at the same time.
> As far as I understand, I think the problem is not Unix, but the way > FreePascal's keyboard unit handles terminal input.
The problem lies in Unix and how you treat input. For example, Nethack and Crawl under Linux react to every escape keypress. Xenocide expects you to hit it twice. As you know, none of these are written in FP.
If you really want escape to be read immediately drop keyboard unit and use crt instead. It works for me. -- Michal Bielinski
Am Thu, 10 Jul 2008 16:47:23 +0200 schrieb Michal Bielinski:
> On Wed, 09 Jul 2008 21:29:45 +0200, Mario Donick > <mario.don...@gmail.com> wrote: >> Am Wed, 09 Jul 2008 11:09:06 -0700 schrieb Krice: >>> If Esc is reserved in unix then it could be wiser to use another key >>> like 'x' or whatever, or make them both work at the same time.
>> As far as I understand, I think the problem is not Unix, but the way >> FreePascal's keyboard unit handles terminal input.
> The problem lies in Unix and how you treat input. For example, Nethack > and Crawl under Linux react to every escape keypress. Xenocide expects > you to hit it twice. As you know, none of these are written in FP.
> If you really want escape to be read immediately drop keyboard unit and > use crt instead. It works for me.
If I remember correctly, I switched to keyboard unit because the FreePascal docs explicitly state that the unit is system independant . It allows me to ignore system-dependant scan codes -- and guarantees me that a key is always recognized the same on every system and every terminal the program might be compiled and run on.
For the same reason, I use the video and vidutil units to do console output instead of Crt.
> Am Thu, 10 Jul 2008 16:47:23 +0200 schrieb Michal Bielinski: > > If you really want escape to be read immediately drop keyboard unit and > > use crt instead. It works for me. > If I remember correctly, I switched to keyboard unit because the > FreePascal docs explicitly state that the unit is system independant . It > allows me to ignore system-dependant scan codes -- and guarantees me that > a key is always recognized the same on every system and every terminal > the program might be compiled and run on. > For the same reason, I use the video and vidutil units to do console > output instead of Crt.
On Linux I use the Graph unit for now(*) and ... Read() for single-press keyboard input for YARL.
((*) Graph has the distinct disadvantage that it uses svgalib, &nb