Inkey problem in graphics mode

General FreeBASIC programming questions.
Post Reply
FotonCat
Posts: 37
Joined: Nov 26, 2009 11:47
Location: Russia
Contact:

Inkey problem in graphics mode

Post by FotonCat »

Hello!

When running this code (same as Inkey example on FB documentation with ScreenRes added) in graphic mode:

Code: Select all

#if __FB_LANG__ = "qb"
#define EXTCHAR Chr$(0)
#else
#define EXTCHAR Chr(255)
#endif

Dim k As STRING

SCREENRES 320,240,32,1,0

Print "Press a key, or Escape to end"
Do

    k = Inkey$

    Select Case k

        Case "A" To "Z", "a" To "z": Print "Letter: " & k
        Case "1" To "9":             Print "Number: " & k

        Case Chr$(32): Print "Space"

        Case Chr$(27): Print "Escape"

        Case Chr$(9): Print "Tab"

        Case Chr$(8): Print "Backspace"

        Case Chr$(32) To Chr$(255)
            Print "Printable character: " & k & STR(ASC(k))

        Case EXTCHAR & "G": Print "Up Left / Home"
        Case EXTCHAR & "H": Print "Up"
        Case EXTCHAR & "I": Print "Up Right / PgUp"

        Case EXTCHAR & "K": Print "Left"
        Case EXTCHAR & "L": Print "Center"
        Case EXTCHAR & "M": Print "Right"

        Case EXTCHAR & "O": Print "Down Left / End"
        Case EXTCHAR & "P": Print "Down"
        Case EXTCHAR & "Q": Print "Down Right / PgDn"

        Case EXTCHAR & "R": Print "Insert"
        Case EXTCHAR & "S": Print "Delete"


        Case EXTCHAR & "k": Print "Close window / Alt-F4"

        Case EXTCHAR & Chr$(59) To EXTCHAR & Chr$(68)
            Print "Function key: F" & Asc(k, 2) - 58

        Case EXTCHAR & Chr$(133) To EXTCHAR & Chr$(134)
            Print "Function key: F" & Asc(k, 2) - 122

        Case Else
            If Len(k) = 2 Then
                Print Using "Extended character: chr$(###, ###)"; Asc(k, 1); Asc(k, 2)
            ElseIf Len(k) = 1 Then
                Print Using "Character chr$(###)"; Asc(k)
            End If

    End Select

    If k = Chr$(27) Then Exit Do

    Sleep 1, 1

Loop

Inkey gives me just a CHR(63) ("?") for every alphabetic keypress (qwertyu.....). For numeric, functional and other keys all works fine.

Only when I tell my OS to use english keyboard layout as a default input, Inkey gives proper values.
In console mode Inkey works fine with any keyboard layout.

Why I can't get cyrillic (CHR(128)...CHR(255)) codes with inkey in graphics mode? Does Inkey only support a 0-127 CHR range in graphics mode?

(Tested on Windows 7 x64 and Windows XP x86)

Thank you for any answer!
Theunis Jansen
Posts: 248
Joined: Jul 01, 2010 9:35

Re: Inkey problem in graphics mode

Post by Theunis Jansen »

Apart from the error define chr$(0) i.e FB when using extended keys no longer recognizes Chr$(0) because for the extended keys they replaced it with Chr(255).

I asked the same questions a year or more ago and was informed that I must use "drawstring" to print letters in graphics mode. I thought that by now it had been "Fixed".
bcohio2001
Posts: 556
Joined: Mar 10, 2007 15:44
Location: Ohio, USA
Contact:

Re: Inkey problem in graphics mode

Post by bcohio2001 »

Take a look at the ScreenEvent() function.

Example from the help file:

Code: Select all

'' include fbgfx.bi for some useful definitions
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
Using fb '' constants and structures are stored in the FB namespace in lang fb
#endif

Dim e As EVENT

ScreenRes 640, 480
Do
    If (ScreenEvent(@e)) Then
        Select Case e.type
        Case EVENT_KEY_PRESS
            If (e.scancode = SC_ESCAPE) Then
                End
            End If
            If (e.ascii > 0) Then
                Print "'" & e.ascii & "'";
            Else
                Print "unknown key";
            End If
            Print " was pressed (scancode " & e.scancode & ")"
        Case EVENT_KEY_RELEASE
            If (e.ascii > 0) Then
                Print "'" & e.ascii & "'";
            Else
                Print "unknown key";
            End If
            Print " was released (scancode " & e.scancode & ")"
        Case EVENT_KEY_REPEAT
            If (e.ascii > 0) Then
                Print "'" & e.ascii & "'";
            Else
                Print "unknown key";
            End If
            Print " is being repeated (scancode " & e.scancode & ")"
        Case EVENT_MOUSE_MOVE
            Print "mouse moved to " & e.x & "," & e.y & " (delta " & e.dx & "," & e.dy & ")"
        Case EVENT_MOUSE_BUTTON_PRESS
            If (e.button = BUTTON_LEFT) Then
                Print "left";
            ElseIf (e.button = BUTTON_RIGHT) Then
                Print "right";
            Else
                Print "middle";
            End If
            Print " button pressed"
        Case EVENT_MOUSE_BUTTON_RELEASE
            If (e.button = BUTTON_LEFT) Then
                Print "left";
            ElseIf (e.button = BUTTON_RIGHT) Then
                Print "right";
            Else
                Print "middle";
            End If
            Print " button released"
        Case EVENT_MOUSE_DOUBLE_CLICK
            If (e.button = BUTTON_LEFT) Then
                Print "left";
            ElseIf (e.button = BUTTON_RIGHT) Then
                Print "right";
            Else
                Print "middle";
            End If
            Print " button double clicked"
        Case EVENT_MOUSE_WHEEL
            Print "mouse wheel moved to position " & e.z
        Case EVENT_MOUSE_ENTER
            Print "mouse moved into program window"
        Case EVENT_MOUSE_EXIT
            Print "mouse moved out of program window"
        Case EVENT_WINDOW_GOT_FOCUS
            Print "program window got focus"
        Case EVENT_WINDOW_LOST_FOCUS
            Print "program window lost focus"
        Case EVENT_WINDOW_CLOSE
            End
        Case EVENT_MOUSE_HWHEEL
            Print "horizontal mouse wheel moved to position " & e.w
        End Select
    End If

    Sleep 1
Loop
FotonCat
Posts: 37
Joined: Nov 26, 2009 11:47
Location: Russia
Contact:

Re: Inkey problem in graphics mode

Post by FotonCat »

I've tried ScreenEvent and it gives proper values for cyrillic keys! :)
Thank you!
Post Reply