'graphical' console in Linux, maybe MAC too

Share your advanced PureBasic knowledge/code with the community.
infratec
Always Here
Always Here
Posts: 7623
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

'graphical' console in Linux, maybe MAC too

Post 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
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

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

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

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

Post 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.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

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

Post 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:
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

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

Post 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. :)
Post Reply