F10 not regtistering with Inkey$

General FreeBASIC programming questions.
Theunis Jansen
Posts: 248
Joined: Jul 01, 2010 9:35

F10 not regtistering with Inkey$

Postby Theunis Jansen » Apr 19, 2013 12:03

i have a program that extensively uses F10 to accept a multi item page. One page has 22 items and another 17.
Using #Lang"fblite" and screen 0 it works perfectly.

The program does not work very well on Vista where I have a tiny screen and fullscreen is not available, and consequently I tried Using screen 17 and #include"FBGFX.BI'
F1 to F9 and F11 to F12 register. I checked Len(Inkey$) and F10 = 0 all the other Function keys = 2.
Thinking my keyboard may have become faulty I connected another one but the problem remains.
Is this perhaps a bug or has F10 been reserved in FBC.

Another point is in screen 0 I have a cursor while in screen 17 and FGX_FULLSCREEN it vanishes. Is there any way that I can make the cursor visible for it is crucial to know on what item the cursor is without having to type something and then erasing it. Using the standard LOCATE ,,1 has no effect.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: F10 not regtistering with Inkey$

Postby MichaelW » Apr 19, 2013 13:30

The F10 key has been reserved by Windows, to activate the menu bar, or in combination with Shift, a context menu.

In my test running a FreeBASIC console app under Window XP Inkey was able to receive the F10 key. Have you tried compiling as a console app and changing the Windows console font size? I don’t know about Vista, but to do so under Windows XP you would right-click the console title bar and select Properties, then in the Properties dialog select the Lucida Console font, then select a size, and click OK. You would then be presented with a dialog asking whether to apply the new properties to the current console only, or to apply them to the current console and save them to be applied to future consoles of the same name. Note that changing the font size changes the console size accordingly, and that on my system the raster fonts are by default displayed at their maximum size.
Theunis Jansen
Posts: 248
Joined: Jul 01, 2010 9:35

Re: F10 not regtistering with Inkey$

Postby Theunis Jansen » Apr 19, 2013 14:39

@MichaelW
Thanks for the info about F10. I already use Enter/ArrowDown/Tab for the next field so maybe I will change F10 to F12 or "Enter"- or is there another key that is more standardized for "Accept"?
Screen 0 is actually the console screen and it works perfectly. I previously implemented what you suggest and with XP there are no problems. All I clicked under the options you refer to, is FULLSCREEN
Reading further on LOCATE I now note that the cursor is only available in console mode so I will have to write my own routine for a quasi-cursor. I last did that about fifteen years ago. But for the sake of that virus named Vista it is not worth the effort. My daughter's 32 bit Vista Premium running on a P4 at 4GHz looks like an old XT with a slipping clutch when it loads a program, starts up or shutsdown.

Such small incompatibilities get me down; I used PCOPY 1,2 with bad results and then found that unlike QB, FB uses 0,1
dodicat
Posts: 6724
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: F10 not regtistering with Inkey$

Postby dodicat » Apr 19, 2013 20:17

Hi Theunis Jansen.

I had this posted in squares topic, but I've included the option of using fblite OR fb.
I think it explains itself, I use Multikey in the main graphics loop, and inkey in the input sub.

By the way, using inkey can be tricky sometimes.
One tip is to use it to assign a letter to it, and access it only through that one letter.

Say dim as string i

then i=inkey in any graphics loop.

if i= this or i= that then blah blah ...
Anyway :

Code: Select all


#lang "fblite"

'DOS fonts, enlarge option
Sub drawstring(xpos As Integer,ypos As Integer,text As String,colour As Uinteger,size As Single,im As Any Pointer=0)
    Type D2
        As Double x,y
        As Uinteger col
    End Type
    Static As d2 cpt(),XY()
    Static As Integer runflag
    If runflag=0 Then   
        Redim  XY(64,256)
        Redim cpt(1 To 64)
        Screenres 10,10  '8 x 8 pixels on this screen
        Dim count As Integer
        For ch As Integer=1 To 256
            Cls
            Draw String(1,1),Chr(ch)
            For x As Integer=1 To 8  'scan for characters
                For y As Integer=1 To 8
                    If Point(x,y)<>0 Then
                        count=count+1
                        XY(count,ch)=Type<D2>(x,y)'save pixel position
                    End If
                Next y
            Next x
            count=0
        Next ch
        runflag=1
       
    End If
    If size=0 Then Exit Sub
    Dim As D2 np,t
    #macro Scale(p1,p2,d)
    np.col=p2.col
    np.x=d*(p2.x-p1.x)+p1.x
    np.y=d*(p2.y-p1.y)+p1.y
    #endmacro
   
    Dim As D2 c=Type<D2>(xpos,ypos)
    Dim As Integer dx=xpos,dy=ypos
    For z6 As Integer=1 To Len(text)
        dim as ubyte asci=text[z6-1]
        If asci=124 Then
            dx=xpos:dy=dy+12:Goto skip 'pipe | for new line
        End If
       
        For _x1 As Integer=1 To 64
            t=Type<D2>(XY(_x1,asci).x+dx,XY(_x1,asci).y+dy,colour)         
            Scale(c,t,size)
            cpt(_x1)=np
           
            If XY(_x1,asci).x<>0 Then 'paint only relevant points
                If Abs(size)>1 Then
                    Line(cpt(_x1).x-size/2,cpt(_x1).y-size/2)-(cpt(_x1).x+size/2,cpt(_x1).y+size/2),cpt(_x1).col,bf
                Else
                    Pset im,(cpt(_x1).x,cpt(_x1).y),cpt(_x1).col
                End If
            End If
        Next _x1
        dx=dx+8
        skip:
    Next z6
End Sub
Sub init Constructor 'automatic loader for fonts
    drawstring(0,0,"",0,0)
    Screen 0
End Sub

'input in a graphics loop
Sub _input(x As Integer,y As Integer,st As String,message As String,size As Single,clr As Uinteger=Rgb(255,255,255))

    Dim As String i=""
    Dim As Integer w=8*Loword(Width)-16*size
    Static As Integer count,gap=30
    Static As String j,blink,msg
    Dim As Integer ln
    count=count+1 Mod 100
    i=Inkey
    If Left(i,1)=Chr(08) Then
        j=Mid(j,1,Len(j)-1)
        msg=Mid(msg,1,Len(msg)-1)
    Elseif Len(i) Then
        j=j+Left(i,1)
        msg=msg+Left(i,1)
    End If
    If count Mod gap=0 Then blink=" "
    If count Mod 2*gap=0 Then blink="_"
    If Left(i,1)=Chr(27) Then j="":msg=""
    If i<>Chr(13) Then
        ln=8*size*(Len(st)+Len(msg)) Mod w
        If ln>=(w -size*8)Then
        If Instrrev(j,"|") <Len(j) Then j=j+"|"
    End If
    drawstring(x,y,st & j & blink,clr,size)
Else
    count=0
    message=Rtrim(msg,Chr(13))
    j="":msg=""
End If
If Lcase(message)="end" Then End
End Sub
'=================================================================


Function framecounter() As Integer
    dim as double t1=Timer,t2=t1
    Static As Double t3,frames,answer
    frames=frames+1
    If (t2-t3)>=1 Then
        t3=t2
        answer=frames
        frames=0
    End If
    Return answer
End Function
'regulate FPS
Function regulate(MyFps As Integer,Byref fps As Integer) As Integer
    fps=framecounter
    Static As Double timervalue
    Static As Double delta,lastsleeptime,sleeptime
    dim as double k=1/myfps
    If Abs(fps-myfps)>1 Then
        If fps<Myfps Then delta=delta-k Else delta=delta+k
    End If
    sleeptime=lastsleeptime+((1/myfps)-(Timer-timervalue))*(2000)+delta
    If sleeptime<1 Then sleeptime=1
    lastsleeptime=sleeptime
    timervalue=Timer
    Return sleeptime
End Function

'some screen graphics - a bird
Sub bird
    Dim As Integer xres,yres
    Screeninfo xres,yres
    Dim As Double PLOT_grade=10000
    Dim As Double temp1,temp2,x1,y1,x
   
    #macro sketch(_function,minx,maxx,miny,maxy)
    For x =minx To maxx Step (maxx-minx)/PLOT_GRADE
        x1=(xres)*(x-minx)/(maxx-minx)
        y1=(yres)*(_function-maxy)/(miny-maxy)
        Pset(x1,y1),Rgb(0,0,10)'10
        If Abs(x)<1e-3 Then
            temp1=x1:temp2=y1
        End If
    Next x
    Circle (temp1,temp2),50,Rgb(0,200,0),,,,f
    Circle (temp1-20,temp2-20),10,Rgb(200,200,200),,,,f
    Circle (temp1+20,temp2-20),10,Rgb(200,200,200),,,,f
   
    Circle (temp1-20-5*z,temp2-20),3,Rgb(00,00,200),,,,f
    Circle (temp1+20-5*z,temp2-20),3,Rgb(00,00,200),,,,f
   
    Circle (temp1,temp2),30,Rgb(0,0,0),4,5.5
    Circle (temp1,temp2-2),30,Rgb(0,0,0),4-k/3,5.5+k/3
    Circle (temp1,temp2),51,Rgb(0,0,10)
    #endmacro
   
    Static k As Integer=1
    Static z As Double
    Dim pi As Double=4*Atn(1)
    z=z+.02*k
    sketch (-Sin(z*x+z),-(pi),pi,-2,2)
    sketch (Sin(z*x-z),-(pi),pi,-2,2)
    Paint (.25*xres,.5*yres),Rgba(100,100,120,190),Rgb(0,0,10)
    Paint (.75*xres,.5*yres),Rgba(100,100,120,190),Rgb(0,0,10)
    If z>1.1 Then k=-k
    If z<-1.1 Then k=-k
    If z>2*pi Then z=0
End Sub
'===================================

'taken from multikey scancodes (help file)

Const AltButton    =56
const F10          =68



const UseAlpha     =64  'instead of including fbgfx.bi

dim as integer xres,yres
Screen 19,32,,UseAlpha
screeninfo xres,yres 'get width/height of graphics screen
'blue background
color ,rgb(0,0,100)


Dim As String message
Dim As Integer inputflag

Dim As Integer fps
Dim As Integer myfps=45
Do
   
    dim as integer SnoozyTime=regulate(myfps,fps)
   
    If Multikey(F10) Then
        inputflag=1  'input mode activated
        'clear the inkey memory
        While Inkey<>"":Wend
        End If
       
        If Multikey(AltButton) Then inputflag=0:message="" 'input mode de-activated
       
        Screenlock
        Cls
        'do some graphics
        bird
        Draw String (10,10),"Press F10 to show input cursor"
        Draw String (10,30),"Press Alt to hide input cursor"
        Draw String (10,50),"Write end at input cursor to finish program"
        Draw String (10,.8*yres),"Frames per second = " &fps
        drawstring .25*xres,.9*yres,"Bird-brain",rgba(200,0,0,50),yres\100
       
        '======== INPUT STUFF =================
        If inputflag Then
            _input 20,.3*yres,"Enter a framerate > ",message,yres\200,Rgb(64,224,208)
        End If
       
        If Valint(message)>5 Then myfps=Valint(message)'at least 5 frames/second
       
        If Len(message) Then ' if you have input something
            dim as string attatch=""
            If Valint(message)<=5 Then attatch=" Too Slow/not valid"
            Draw String(20,.85*yres),"You entered        " & message & attatch
        End If
        '==========================================
        Screenunlock
        Sleep SnoozyTime,1
    Loop
   
    Sleep
     

Return to “General”

Who is online

Users browsing this forum: No registered users and 14 guests