Search the web
Sign In
New User? Sign Up
forth200x
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
RfD: EKEY return values   Message List  
Reply | Forward Message #54 of 425 |
2nd RfD: EKEY return values

The HTML version of this RfD is <http://www.forth200x.org/ekeys.html>

Change History

2006-05-28
Added K-INSERT, K-DELETE, K-F* and K-*-MASK. Added Sections
Programming Advice and Shift Keys. Reported comments by various
people.


Problem

How do I write a portable Forth program that reacts to key presses of
cursor keys (and possibly other keys not represented by ASCII), e.g., an
editor?


Proposal

The following words produce the same values that EKEY produces when the
user presses the corresponding key.

K-LEFT ( -- u ) facility ext
The "cursor left" key

K-RIGHT ( -- u ) facility ext
The "cursor right" key

K-UP ( -- u ) facility ext
The "cursor up" key

K-DOWN ( -- u ) facility ext
The "cursor down" key

K-HOME ( -- u ) facility ext
The "home" or "Pos1" key

K-END ( -- u ) facility ext
The "End" key

K-PRIOR ( -- u ) facility ext
The "PgUp" or "Prior" key

K-NEXT ( -- u ) facility ext
The "PgDn" or "Next" key

K-INSERT ( -- u ) facility ext
The "Insert" key

K-DELETE ( -- u ) facility ext
The "Delete" key

K-F1 ( -- u ) facility ext
The "F1" key

K-F2 ( -- u ) facility ext
The "F2" key

K-F3 ( -- u ) facility ext
The "F3" key

K-F4 ( -- u ) facility ext
The "F4" key

K-F5 ( -- u ) facility ext
The "F5" key

K-F6 ( -- u ) facility ext
The "F6" key

K-F7 ( -- u ) facility ext
The "F7" key

K-F8 ( -- u ) facility ext
The "F8" key

K-F9 ( -- u ) facility ext
The "F9" key

K-F10 ( -- u ) facility ext
The "F10" key

K-F11 ( -- u ) facility ext
The "F11" key

K-F12 ( -- u ) facility ext
The "F12" key

The following words procude a mask, that you can OR with the key values
above to produce a value that EKEY may produce when the user presses the
corresponding key combination.

K-SHIFT-MASK ( -- u ) facility ext
Mask for the shift key

K-CTRL-MASK ( -- u ) facility ext
Mask for the ctrl key

K-ALT-MASK ( -- u ) facility ext
Mask for the alt key


Typical Use

... ekey case
k-up of ... endof
k-f1 of ... endof
k-left k-shift or k-ctrl or of ... endof
...
endcase


Remarks

Programming advice

Note that, even if a Forth system supports these words, many environments
do not have or do not report all these keys and key combinations, so it
is a good idea to write your program such that it is still useful even if
these keys and key combinations cannot be pressed or are not recognized.

Shift keys

Note that, as defined, the shift key masks defined above are only useful
for recognizing shifted cursor and function keys, because these are the
only keys that EKEY return values are defined for. E.g., we cannot
program Forth to recognize recognize ALT-T, because no EKEY return value
for T has been defined.

Other Keys

Gforth and PFE have words K1...K10 for the function/keypad keys; they
also contain S-K1...S-K10 for shifted function/keypad keys, but they
don't work as widely. Moreover, Gforth (but not PFE) also has K-INSERT
K-DELETE K11 K12 S-K11 S-K12. Should any of these words be added to this
proposal? After the first RfD, several people were in favour of adding
such words and nobody spoke out against, so I added the words after
K-NEXT. If you don't like such words in general, or would like them, but
differently, please speak up now.


Experience

These words have been implemented for several years in PFE and
Gforth. Several editors have been published in ANS Forth that would
have profited from these words. Also, the original version of the
MiniSpreadsheet <http://wiki.forthfreak.net/index.cgi?MiniSpreadsheet>
hardcoded the values for the keys for one platform; I then fixed it to
use the cursor-key words proposed above.


Implementation and Tests

The implementation is closely tied to the implementation of EKEY, and
therefore unportable, so I don't provide a reference
implementation. However, you can look at the Gforth implementation
<http://b2.complang.tuwien.ac.at/cgi-bin/cvsweb/~checkout~/gforth/ekey.fs?rev=HE\
AD;content-type=text%2Fplain;cvsroot=gforth
>
of EKEY and many of these words (based on ANSI terminal escape
sequences).

Tests <http://www.complang.tuwien.ac.at/forth/ansforth/tests/ekeys.fs>


Comments

Alex McDonald writes:

Win32Forth provides;

k_home k_up k_pgup k_left k_right k_end k_down k_pgdn k_insert
k_delete k_scroll

plus k_1 through k_12 for function keys.

+k_control +k_alt +k_shift provide a mask when these keys are depressed
with any of the above.

Marcel Hendrix writes <13073534183561@...> that iForth
implements this functionality, but with different key names.

Charles Melice and Alex McDonald would prefer K-F1 etc. for function
keys, and masks for shifted keys etc.

Charles Melice would also like to see some events defined for mouse
events (<44734824$0$20278$ba620e4c@...> ff.). There was some
discussion on how that should be done; however, it will not be done in
this proposal.

Robert Epprecht uses these words and would like to have them available in
different Forth implementations. Also, he would like to see the words for
the function keys.

- anton



Sun May 28, 2006 4:31 pm

anton@...
Send Email Send Email

Forward
Message #54 of 425 |
Expand Messages Author Sort by Date

... [ ... ] ... I would like to see them all added to this proposal. ... I *do* use them. It would be very desirable to have the same words available in...
Robert Epprecht
epprecht@...
Send Email
May 24, 2006
6:38 am

The HTML version of this RfD is <http://www.forth200x.org/ekeys.html> Change History 2006-05-28 Added K-INSERT, K-DELETE, K-F* and K-*-MASK. Added Sections ...
Anton Ertl
anton@...
Send Email
May 28, 2006
4:32 pm

... I think of applications in three basic groups: embedded mobile/PDA desktop This proposal is firmly in the desktop arena. IMHO it introduces unspecified...
Stephen Pelc
sfprem
Offline Send Email
May 30, 2006
11:18 am

... Yes. It's certainly not useful for programs that run on computers without keyboards. ... No such linkages are intended. Why do you think that this...
Anton Ertl
anton@...
Send Email
Jun 3, 2006
2:39 pm

... KEY is not just used for keyboards! On our systems, both desktop and embedded, KEY, EMIT and friends can be vectored on a task/thread/callback specific...
Stephen Pelc
sfprem
Offline Send Email
Jun 5, 2006
11:01 am

... Not really. The PC has a 8042 based keyboard, which is then translated to the X keyboard event (which is an abstraction for quite a number of different...
Bernd Paysan
berndpaysan
Offline Send Email
Jun 5, 2006
1:05 pm

... I take your point, but both start from the Linux kernel and libc. There are other operating systems. The point at issue is really that the proposal seems...
Stephen Pelc
sfprem
Offline Send Email
Jun 5, 2006
2:55 pm

... From VAX to zSeries: They all can work with X servers, by mapping key strokes to KeySyms. And the same works on Windows and Mac OS, which are again...
Bernd Paysan
berndpaysan
Offline Send Email
Jun 5, 2006
5:01 pm

... Not all desktops are PCs, or has this become a generic term for a desktop computer? ... My question was under the O/S API. I doubt if gForth does, and a ...
Stephen Pelc
sfprem
Offline Send Email
Jun 5, 2006
11:10 pm

... Well, originally a PC was a "personal computer", i.e. one for yourself, not one with a terminal attached. Seems to be similar to the term "desktop...
Bernd Paysan
berndpaysan
Offline Send Email
Jun 6, 2006
12:04 am

... EKEY? should return true if EKEY won't block. KEY? should return true if KEY won't block. If KEY just discards the PgUp key and then waits for you to type...
Anton Ertl
anton@...
Send Email
Jun 6, 2006
7:13 am

... But you're still assuming X or some OS intermediary between you and the chipset. There are purely native PC Forths, such as Greg Bailey's, not to mention...
Elizabeth D Rather
erather
Offline Send Email
Jun 6, 2006
12:19 am

... I don't see a problem there. Your EKEY will do on these devices whatever it has always done. If that does not include recognizing cursor and function...
Anton Ertl
anton@...
Send Email
Jun 6, 2006
7:05 am

... If I write a program, that uses certain keys, I want to know if they are there. If I want to make it usable on systems that don't provide them, I would use...
Robert Epprecht
epprecht@...
Send Email
Jun 6, 2006
3:18 pm

... The Forth system may not know if the keys are available. Gforth certainly does not know it (and even if they are available on the system, they might...
Anton Ertl
anton@...
Send Email
Jun 18, 2006
8:42 pm

... Valid points. ... I do. But I also use a lot of key bindings in my programs as they are often much more convenient then the 'other means'. So I often run...
Robert Epprecht
epprecht@...
Send Email
Jun 21, 2006
1:16 pm

... I may start to see what the point of this labeling stuff is: If you sell a Forth system for a keyboard-less embedded system to some customers, and they ask...
Anton Ertl
anton@...
Send Email
Jun 6, 2006
7:40 am

... Partly. Let's change desktop to PC from now on. The behaviour of KEY or EKEY on a PC depends on what they are connected to. The EKEY return value proposal...
Stephen Pelc
sfprem
Offline Send Email
Jun 6, 2006
10:36 am

... Yes. So I don't see what the problem is. ... Sounds fine to me. Although I wonder why you would need to change even that. What does it currently do if...
Anton Ertl
anton@...
Send Email
Jun 18, 2006
9:29 pm

... Or the Forth200x standard could make it clear somehow, that parts of it which are not relevant on a certain system and hardware can be omitted without...
Robert Epprecht
epprecht@...
Send Email
Jun 6, 2006
2:35 pm

... If you read the "Compliance and Labeling" sections of the current standard, you'll see that it bends over backwards to make this clear. The Core wordset is...
Elizabeth D Rather
erather
Offline Send Email
Jun 6, 2006
6:48 pm

In Open Firmware land, we stopped using the IEEE standardization process and starting labeling every new thing as a "Recommended Practice". That worked really...
Mitch Bradley
wmb@...
Send Email
Jun 6, 2006
9:10 pm

... Interesting. We have had some discussions on whether and how to work with an official standards body. - anton...
Anton Ertl
anton@...
Send Email
Jun 18, 2006
8:17 pm

A data point, for what it's worth: In Quartus Forth (for Palm Pilots), EKEY returns 'event_type', a value from a rather small set. To get anything...
Mitch Bradley
wmb@...
Send Email
Jun 6, 2006
9:23 pm

... Thanks for the info. I will contact Neal Bridges and as him what he thinks about the proposal. ... Yes, there were some discussions on comp.lang.forth...
Anton Ertl
anton@...
Send Email
Jun 18, 2006
8:10 pm

... What I meant by the note was that EKEY might be vectored, so that the user could point it at different keyboards with different extended code sets. The...
Mitch Bradley
wmb@...
Send Email
Jun 18, 2006
11:24 pm

... Well, that seems to be outside standardisation (at least at the moment), so if a system supports that, I would expect it to clarify what happens in this...
Anton Ertl
anton@...
Send Email
Jun 19, 2006
8:42 pm

... okay by me....
Mitch Bradley
wmb@...
Send Email
Jun 20, 2006
11:12 pm

... The normal case would be that KEY ignores the <cursor down>, so KEY? should return false. The abnormal case is if the <cursor down> is visible as escape...
Anton Ertl
anton@...
Send Email
Jun 18, 2006
10:03 pm

... If you then use KEY and no further magic key events occur, what does/should EKEY? then return? Stephen...
stephen@...
sfprem
Offline Send Email
Jun 19, 2006
8:35 am
 First  |  |  Last 
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help