Hi, I am running a console-mode program on an RS232 text dumb terminal.
The terminal hardware sends escape sequence keycodes for the F-keys, arrow keys, etc.
Example: Pressing F1 makes the terminal send: Ctrl+A, @, <CR>
In other words Chr$(1), Chr$(64), Chr$(13)
Problem: Inkey, Getkey, and Multikey return unpredictable results with these long multi-character scancodes.
Problem: Keycodes are variable length. Some send 3 characters like above example, others are 1-6 characters long.
Problem: Not all keycodes end with Chr$(13), so Input # with the Cons OPENed as an input file doesn't work in all cases. Input # doen't terminate until it finds an EOL character.
Info: The RS232 terminal can be set to send hex scancodes for all keys (including QWERTY) instead of ASCII characters. However I don't know how to receive this input into my FreeBASIC program? Linux can't handle the hex scancodes internally, and because Multikey and Getkey map to Linux's terminfo function, they break too.
How to grab escape-sequence keycodes?
-
- Posts: 862
- Joined: May 05, 2015 5:35
- Location: Germany
Re: How to grab escape-sequence keycodes?
Maybe try Get# instead of Input# (sorry, can't test it here now due to lack of time :-( )
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: How to grab escape-sequence keycodes?
"... Inkey, Getkey, and Multikey ..."
What have this functions to do with a RS-232 connection ?
In FreeBASIC a RS-232 connection is like a file read / write operation.
KeyPgOpenCom
Joshy
What have this functions to do with a RS-232 connection ?
In FreeBASIC a RS-232 connection is like a file read / write operation.
KeyPgOpenCom
Joshy
Re: How to grab escape-sequence keycodes?
The RS232 terminal is a text console, i.e. attached to Linux as stdin/stdout.D.J.Peters wrote:"... Inkey, Getkey, and Multikey ..."
What have this functions to do with a RS-232 connection ?
In FreeBASIC a RS-232 connection is like a file read / write operation.
KeyPgOpenCom
Joshy
It is accessed inside FreeBASIC using "Open Cons:"
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: How to grab escape-sequence keycodes?
Code: Select all
var hFile = FreeFile()
Open Cons For Input As #hFile
var aborted=false
while aborted = false
var ASingleChar = Input(1,hFile)
if ASingleChar<>"" then
if ASingleChar[0] = 1 then
var TwoChars = Input(2,hFile)
if TwoChars[0]=64 andalso TwoChars[1]=13 then
print "F1 are pressed !"
end if
elseif ASingleChar[0] = 12 then
'....
end if
end if
'if inkey()=asc(27) then aborted=true
wend
close #hFile
print "done ..."
Re: How to grab escape-sequence keycodes?
It seems, that we are talking about two different things.
This needs some clarification first.
If you are connecting to a hardware (physical) terminal, then I think:
Joshi is correct (and the FB command is: Open COM)
And, atachement to Linux Terminals IO streams, whould not be correct.
This needs some clarification first.
If you are connecting to a hardware (physical) terminal, then I think:
Joshi is correct (and the FB command is: Open COM)
And, atachement to Linux Terminals IO streams, whould not be correct.
Re: How to grab escape-sequence keycodes?
The text terminal is on an RS232-to-USB converter, running on the Linux box as /dev/ttyUSB2MrSwiss wrote:It seems, that we are talking about two different things.
This needs some clarification first.
If you are connecting to a hardware (physical) terminal, then I think:
Joshi is correct (and the FB command is: Open COM)
And, atachement to Linux Terminals IO streams, whould not be correct.
The shell session running on the terminal sees the terminal as stdin and stdout.
So using a PRINT command in fb causes output to the terminal.
The QWERTY keys work fine with Input, Getkey, Multikey, etc., because they use standard ASCII scancodes.
But the arrow, function, etc., keys do not work because they send special control codes and escape sequences unique to my terminal.
How can I capture these special control codes in my program? For example, how do I capture the "Chr$(1) & Chr$(64) & Chr$(13)" sent by the terminal when I press F1?
-
- Posts: 8586
- Joined: May 28, 2005 3:28
- Contact:
Re: How to grab escape-sequence keycodes?
If you read from stdin you use
Open Cons For Input As #hFile
then my posted solution will work
if not why
you can post the code also
Joshy
Open Cons For Input As #hFile
then my posted solution will work
if not why
you can post the code also
Joshy
Re: How to grab escape-sequence keycodes?
Thank you D.J.Peters, your code solved my problem!D.J.Peters wrote:If you read from stdin you use
Open Cons For Input As #hFile
then my posted solution will work
if not why
you can post the code also
Joshy