Page 1 of 1

'graphical' console in Linux, maybe MAC too

Posted: Sun Jan 17, 2010 11:13 am
by infratec
Hi,

I had to write a small console program in Linux and notified,
that ConsoleClear(), ConsoleLocate() and ConsoleColor() is only for Windo..

If you want to know how it is possible to use such features, look here:
http://www.purebasic.fr/english/viewtop ... 93#p312593

I hope this functions will be implemented in a later version of PB

Bernd

Re: 'graphical' console in Linux, maybe MAC too

Posted: Thu Jan 21, 2010 7:46 am
by GBeebe
While we're on the subject, I also figured out how to capture arrow keys.
The Inkey() example, in the help, quits when an arrow key is pressed, it's because these keys return Esc codes too.

Esc[A = Up
Esc[B = Down
Esc[C = Right
Esc[D = Left

Here is my altered Inkey() help

Code: Select all

If OpenConsole()
    PrintN("Press Escape to exit")
  
    Repeat
        KeyPressed$ = Inkey()
      
        If KeyPressed$ <> ""
        
            PrintN("You pressed: " + KeyPressed$)
            PrintN("It has a raw code of: "+Str(RawKey()))
        
            If RawKey() = 27
                k.s = Inkey()
                If RawKey() <> 0    ; Special key
                    KeyPressed$ = Inkey()
                    Select KeyPressed$
                        Case "A"
                            PrintN("You Pressed UP")
                        Case "B"
                            PrintN("You Pressed DOWN")
                        Case "C"
                            PrintN("You Pressed RIGHT")
                        Case "D"
                            PrintN("You Pressed LEFT")
                    EndSelect
                EndIf
            EndIf
    
        ElseIf RawKey()
      
            PrintN("You pressed a non ASCII key.")
            PrintN("It has a raw code of: "+Str(RawKey()))
        
        Else
            Delay(20) ; Don't eat all the CPU time, we're on a multitask OS
        EndIf
    
        Until KeyPressed$ = Chr(27) ; Wait until escape is pressed
  EndIf

Re: 'graphical' console in Linux, maybe MAC too

Posted: Thu Jan 21, 2010 8:25 am
by Demivec
GBeebe wrote:While we're on the subject, I also figured out how to capture arrow keys.
The Inkey() example, in the help, quits when an arrow key is pressed, it's because these keys return Esc codes too.

Esc[A = Up
Esc[B = Down
Esc[C = Right
Esc[D = Left
@GBeebe: When I run your code sample and press the arrow keys it displays "You pressed a non ASCII key" and the raw codes 38 -> 40.

I'm running Win XP SP3 32-bit.

Re: 'graphical' console in Linux, maybe MAC too

Posted: Thu Jan 21, 2010 6:43 pm
by fsw
Demivec wrote:
GBeebe wrote:While we're on the subject, I also figured out how to capture arrow keys.
The Inkey() example, in the help, quits when an arrow key is pressed, it's because these keys return Esc codes too.

Esc[A = Up
Esc[B = Down
Esc[C = Right
Esc[D = Left
@GBeebe: When I run your code sample and press the arrow keys it displays "You pressed a non ASCII key" and the raw codes 38 -> 40.

I'm running Win XP SP3 32-bit.
The title says:
'graphical' console in Linux, maybe MAC too
You are running:
Demivec wrote:I'm running Win XP SP3 32-bit.
:shock:

Re: 'graphical' console in Linux, maybe MAC too

Posted: Thu Jan 21, 2010 6:56 pm
by Demivec
fsw wrote:The title says:
'graphical' console in Linux, maybe MAC too
You are running:
Demivec wrote:I'm running Win XP SP3 32-bit.
:shock:
My appologies, I did check the forum (and it wasn't Linux but Tricks n' Tips) but neglected to check the thread title itself.

I think one of my light bulbs burned out.

:idea: Now it's back on again. :)