Google Groups Home
Help | Sign in
Accessing ESC key in FreePascal
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  14 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Mario Donick  
View profile
 More options 4 Jul, 11:01
Newsgroups: rec.games.roguelike.development
From: Mario Donick <mario.don...@gmail.com>
Date: 04 Jul 2008 10:01:39 GMT
Local: Fri 4 Jul 2008 11:01
Subject: Accessing ESC key in FreePascal
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:

var
  k: TKeyEvent;
  ks: String;

begin
  k:=GetKeyEvent;
  k:=TranslateKeyEvent(k);
  ks:=KeyEventToString(k);

  if ks='Left' then
    // move left;

  if ks='Right' then
    // move right;

  // and so on ...
end;

This works system independantly for most keys -- but not for the Escape
key which sometimes is not returned at all, sometimes as "ALT" modifier.

Has anybody some hints for me?

Mario Donick

--
LambdaRogue -- The Book of Stars (http://donick.net/lr)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michal Bielinski  
View profile
 More options 4 Jul, 15:56
Newsgroups: rec.games.roguelike.development
From: "Michal Bielinski" <Dungeon_Kee...@tlen.pl>
Date: Fri, 04 Jul 2008 16:56:15 +0200
Local: Fri 4 Jul 2008 15:56
Subject: Re: Accessing ESC key in FreePascal
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mario Donick  
View profile
 More options 4 Jul, 16:36
Newsgroups: rec.games.roguelike.development
From: Mario Donick <mario.don...@gmail.com>
Date: 04 Jul 2008 15:36:44 GMT
Local: Fri 4 Jul 2008 16:36
Subject: Re: Accessing ESC key in FreePascal
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?" ;-)

Thank you for the hints :)

Mario Donick

--
LambdaRogue -- The Book of Stars (http://donick.net/lr)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michal Bielinski  
View profile
 More options 4 Jul, 19:27
Newsgroups: rec.games.roguelike.development
From: "Michal Bielinski" <Dungeon_Kee...@tlen.pl>
Date: Fri, 04 Jul 2008 20:27:05 +0200
Local: Fri 4 Jul 2008 19:27
Subject: Re: Accessing ESC key in FreePascal

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.

Full explanation (reference for unit 'keyboard'):
http://community.freepascal.org:10000/docs-html/rtl/keyboard/kbdunix....

The same thing was with tilde under DOS. ADoM used ' as a replacement key.

> I already see the complaints of Krice (although he might not use Unix):
> "Why do I have to press ESC twice? Are you retarded?" ;-)

Perhaps choose another key to function like escape?
--
Michal Bielinski

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mario Donick  
View profile
 More options 4 Jul, 20:34
Newsgroups: rec.games.roguelike.development
From: Mario Donick <mario.don...@gmail.com>
Date: 04 Jul 2008 19:34:20 GMT
Local: Fri 4 Jul 2008 20:34
Subject: Re: Accessing ESC key in FreePascal
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.

> Full explanation (reference for unit 'keyboard'):
> http://community.freepascal.org:10000/docs-html/rtl/keyboard/

kbdunix.html

Thanks. I did not know that.

> Perhaps choose another key to function like escape?

Hehe, in several menus I used SPACE to escape, but people told me that
ESC is more standard. Now I use ESC, even if they need to press it 2
times.

Mario

--
LambdaRogue -- The Book of Stars (http://donick.net/lr)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kornel Kisielewicz  
View profile
 More options 7 Jul, 01:35
Newsgroups: rec.games.roguelike.development
From: Kornel Kisielewicz <admin@nospam_chaosforge.org>
Date: Mon, 07 Jul 2008 02:35:49 +0200
Local: Mon 7 Jul 2008 01:35
Subject: Re: Accessing ESC key in FreePascal
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.

regards,
Kornel Kisielewicz


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michal Bielinski  
View profile
 More options 9 Jul, 11:43
Newsgroups: rec.games.roguelike.development
From: "Michal Bielinski" <Dungeon_Kee...@tlen.pl>
Date: Wed, 09 Jul 2008 12:43:17 +0200
Local: Wed 9 Jul 2008 11:43
Subject: Re: Accessing ESC key in FreePascal

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

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Krice  
View profile
 More options 9 Jul, 19:09
Newsgroups: rec.games.roguelike.development
From: Krice <pau...@mbnet.fi>
Date: Wed, 9 Jul 2008 11:09:06 -0700 (PDT)
Local: Wed 9 Jul 2008 19:09
Subject: Re: Accessing ESC key in FreePascal
On 4 heinä, 22:34, Mario Donick <mario.don...@gmail.com> wrote:

> Now I use ESC, even if they need to press it 2 times.

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.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mario Donick  
View profile
 More options 9 Jul, 20:29
Newsgroups: rec.games.roguelike.development
From: Mario Donick <mario.don...@gmail.com>
Date: 09 Jul 2008 19:29:45 GMT
Local: Wed 9 Jul 2008 20:29
Subject: Re: Accessing ESC key in FreePascal
Am Wed, 09 Jul 2008 11:09:06 -0700 schrieb Krice:

> On 4 heinä, 22:34, Mario Donick <mario.don...@gmail.com> wrote:
>> Now I use ESC, even if they need to press it 2 times.

> 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.

--
LambdaRogue -- The Book of Stars (http://donick.net/lr)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michal Bielinski  
View profile
 More options 10 Jul, 15:47
Newsgroups: rec.games.roguelike.development
From: "Michal Bielinski" <Dungeon_Kee...@tlen.pl>
Date: Thu, 10 Jul 2008 16:47:23 +0200
Local: Thurs 10 Jul 2008 15:47
Subject: Re: Accessing ESC key in FreePascal

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mario Donick  
View profile
 More options 10 Jul, 16:34
Newsgroups: rec.games.roguelike.development
From: Mario Donick <mario.don...@gmail.com>
Date: 10 Jul 2008 15:34:10 GMT
Local: Thurs 10 Jul 2008 16:34
Subject: Re: Accessing ESC key in FreePascal
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.

--
LambdaRogue -- The Book of Stars (http://donick.net/lr)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jürgen Lerch  
View profile
 More options 10 Jul, 21:18
Newsgroups: rec.games.roguelike.development
From: "Jürgen Lerch" <jyn...@gmx.de>
Date: 10 Jul 2008 21:18:12 +0100
Local: Thurs 10 Jul 2008 21:18
Subject: Re: Accessing ESC key in FreePascal
Saluton!

On 10 Jul 2008 15:34:10 GMT, Mario Donick wrote:

> 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