Where to put keyboard code

General FreeBASIC programming questions.
badidea
Posts: 1182
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Where to put keyboard code

Postby badidea » Jan 12, 2019 21:36

Gablea wrote:Now I just have to work out how to use your code badidea :D

Similar but different:

Code: Select all

#include "fbgfx.bi"
#include "vbcompat.bi"

const as integer QUIT_SCREEN = 0
const as integer BACKGROUND_SCREEN = 1
const as integer SIGNED_ON_SCREEN = 2
const as integer SCRN_W = 800, SCRN_H = 600

'-------------------------------------------------------------------------------

type Background_type
   dim as integer unusedVariable
   declare sub Display()
   declare sub HandleInput(key as string, byref state as integer)
end type

sub Background_type.Display()
   line(60, 60)-(SCRN_W - 60, SCRN_H - 60), &h00440044, bf
   draw string (70, 70), "BACKGROUND_SCREEN"
   draw string (70, 90), format(now, "yyyy-mm-dd hh:mm:ss")
   locate 2, 1: print "Press <ENTER> for SignedOnScreen";
   locate 3, 1: print "Press <ESCAPE> to exit program  ";
end sub

sub Background_type.HandleInput(key as string, byref state as integer)
   select case key
   case chr(13)
      state = SIGNED_ON_SCREEN
   case chr(27)
      state = QUIT_SCREEN
   case else
   end select
end sub

'-------------------------------------------------------------------------------

type SignedOnScreen_type
   dim as string userName
   declare sub Display()
   declare sub HandleInput(key as string, byref state as integer)
end type

sub SignedOnScreen_type.Display()
   line(160, 160)-(SCRN_W - 160, SCRN_H - 160), &h00004444, bf
   draw string (170, 170), "SIGNED_ON_SCREEN"
   draw string (170, 190), "userName: " + userName
   locate 2, 1: print "Press <ESCAPE> to go back       ";
   locate 3, 1: print "Try typing user name ...        ";
end sub

sub SignedOnScreen_type.HandleInput(key as string, byref state as integer)
   select case key
   case chr(27)
      state = BACKGROUND_SCREEN
   case chr(33) to chr(126) 'somwhat normal characters
      if len(userName) < 40 then
         userName += key
      end if
   case chr(8) 'backspace
      if len(userName) > 0 then
         userName = left(userName, len(userName) - 1)
      end if
   case else
   end select
end sub

'-------------------------------------------------------------------------------

screenres SCRN_W, SCRN_H, 32
width SCRN_W \ 8, SCRN_H \ 16

'Makes instances of the about classes 
dim as Background_type Background
dim as SignedOnScreen_type SignedOnScreen
 
dim as string key
dim as integer state = BACKGROUND_SCREEN
do
   key = inkey
   select case state
   case BACKGROUND_SCREEN
      Background.HandleInput(key, state)
   case SIGNED_ON_SCREEN
      SignedOnScreen.HandleInput(key, state)
   end select

   screenlock
   Background.Display() 'always
   locate 1, 1: print "state: " + str(state);
   if state = SIGNED_ON_SCREEN then SignedOnScreen.Display()
   screenunlock

   sleep 1, 1
loop until state = QUIT_SCREEN
dodicat
Posts: 5563
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Where to put keyboard code

Postby dodicat » Jan 12, 2019 22:11

similar but using F2 key for username

Code: Select all

  #include "fbgfx.bi"
#include "vbcompat.bi"

Using FB '' Screen mode flags are in the FB namespace in lang FB

Declare Sub DisplayBackground(as string)' (ByVal CurrentTime As String, ByVal CurrentDate As String)
Declare Sub DisplaySignedOnScreen(as string)

Screen 19, 32,2 , (GFX_WINDOWED Or GFX_NO_SWITCH)

Sub _input(st As String,message As String,hide as long=0)
    #macro split(stri)
    If p<>0 Then
        Var e=Len(j)-p
        var1=Mid(stri,1,e)
        var2=Mid(stri,e+1)
    Else
        var1=stri
    End If
    #endmacro
    #define condition Right(i,1)<>"M" And Right(i,1)<>"K"
    Dim As String i=""
    Static As Long k=1
    Static As String j,blink
    Static As Double t
    Static As Long p
    Static As String var1,var2,copy
    while len(i)<>0:wend 
    i=Inkey
    If p=0 Then
        If Left(i,1)=Chr(08) Then j=Mid(j,1,Len(j)-1)
    Else
        If Left(i,1)=Chr(08) Then var1=Mid(var1,1,Len(var1)-1)
    End If
   
    If p=0 Then 
        If Left(i,1)<>Chr(08) And condition Then j=j+Left(i,1)
    End If
    If i= Chr(255) + "M"  Then j+=" "
    If i= Chr(255) + "K"  Then: p+=1:split(j):End If
    if p>len(j) then p=len(j)
    split(j)
    If p  And condition Then j=var1+Left(i,1)+var2
   
    If Timer-t>.5 Then
        t=Timer
        k=-k
        If k=1 Then blink=" " Else blink=Chr(223)
    End If
   
    If Left(i,1)=Chr(27) Then j=""
    If i<>Chr(13) Then
        if hide =0 then
        Print st & j;
        Locate Csrlin+1,Pos-p
        Print blink
        copy=j
    else
       Print st & string(len(j),"*");
        Locate Csrlin+1,Pos-p
        Print blink
        copy=j
        end if
    Else
        copy=Rtrim(copy,Chr(13))
        message=copy
        j=""
        p=0
        var1=""
        var2=""
        copy=""
    End If
End Sub

function user(flag as long,s as string) as long
     
dim as long c=csrlin,p=pos
dim as long fin=1
    Locate c,p,0
    if flag=1 then _input("Username   ",s)
    if flag=2 then _input("Enter password   ",s,1)  'unused here
    Sleep 20,1
    if len(s) then fin=0
    return fin
end function



dim  as string info
dim shared as string key
dim shared as long show
screenset 1,0
Do


cls
if show=0 then
    ' do stuff
    var i=inkey
    if i=chr(13) then i+=chr(10)
    key+=i
end if


   DisplayBackground(info)
   if multikey(SC_F2)  then
        while inkey<>"":wend     'clear the keyboard mem
    show=1:info=""
    key=rtrim(key,chr(255)+"<") 'get rid of f2
    end if
   
   if show=1 then
    DisplaySignedOnScreen(info)
    end if

   flip
   sleep 10,1
Loop until multikey(sC_ESCAPE)

sub displaybackground(info as string)
    locate 2
    print "Press F2 for username"
    print Format(Now,"HH:MM:ss")
    locate 9
    print "Do stuff (print username)"
    print "Username:   ";info
    locate 14
     print key
    end sub
   
Private Sub DisplaySignedOnScreen(s as string)
   Dim DisplayWidth As Integer = 40
   Locate 5,5
   Print Chr(218) & String(DisplayWidth,Chr(196)) & Chr(191);
   Locate 6,5
   Print Chr(179) & String(DisplayWidth," ") & Chr(179);
   Locate 7,5
   Print Chr(179) & String(DisplayWidth," ") & Chr(179);
   Locate 8,5
   Print Chr(192) & String(DisplayWidth,Chr(196)) & Chr(217);
   locate 6,9
   show= user(1,s)
End Sub   
Last edited by dodicat on Jan 13, 2019 16:04, edited 2 times in total.
Gablea
Posts: 1037
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Where to put keyboard code

Postby Gablea » Jan 13, 2019 11:56

Thank you for the other examples.

And badidea I’ve never had a problem with the scanners as they have always sent the end chr (chr(13) they can do a lot more then just send a barcode as they also have a scale connected. I was sent a small C program that reads the scanner data and splits off either the barcode or weight but I’ve never beable to understand it as like I said it’s in C. I could post the source code here if anyone could translate it to FB.
badidea
Posts: 1182
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Where to put keyboard code

Postby badidea » Jan 13, 2019 13:35

dodicat wrote:similar but using F2 key for username

The combination of multikey & inkey does work too well: Press some keys in main loop and then F2.
grindstone
Posts: 637
Joined: May 05, 2015 5:35
Location: Germany

Re: Where to put keyboard code

Postby grindstone » Jan 13, 2019 14:09

Gablea wrote:I could post the source code here if anyone could translate it to FB.
I volunteer.
dodicat
Posts: 5563
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Where to put keyboard code

Postby dodicat » Jan 13, 2019 14:51

badidea wrote:
dodicat wrote:similar but using F2 key for username

The combination of multikey & inkey does work too well: Press some keys in main loop and then F2.


Thanks Badidea, forgot to clear the keyboard memory.
fixed it.
Gablea
Posts: 1037
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Where to put keyboard code

Postby Gablea » Jan 13, 2019 16:48

grindstone wrote:
Gablea wrote:I could post the source code here if anyone could translate it to FB.
I volunteer.


Thank you so much grindstone I’ll upload it once I get to my PC
Gablea
Posts: 1037
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Where to put keyboard code

Postby Gablea » Jan 13, 2019 17:39

grindstone wrote:
Gablea wrote:I could post the source code here if anyone could translate it to FB.
I volunteer.


Hi grindstone,

Here is the C program that takes either weight or barcode data from the scanner

This example writes the data to a table within a MySQL database but i am sure there are ways to send data to a Freebasic app (ie via tcp socket connection)

click here to download (http://support.algpos.co.uk/freebasic/rs232.7z)
grindstone
Posts: 637
Joined: May 05, 2015 5:35
Location: Germany

Re: Where to put keyboard code

Postby grindstone » Jan 13, 2019 17:57

Sorry, I can't unpack that archive ("Unsupported compression method"). I get a list of files, but all empty (0 Bytes).
dodicat
Posts: 5563
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Where to put keyboard code

Postby dodicat » Jan 13, 2019 18:10

grindstone.
7-zip unpacks it.
I have 7-Zip portable on win 10.
The .c file doesn't compile on Win, so I cannot even create a library, it is a Linux file.
If you cannot get 7-zip I can put the unpacked files on mediafire in a .zip if you like.
grindstone
Posts: 637
Joined: May 05, 2015 5:35
Location: Germany

Re: Where to put keyboard code

Postby grindstone » Jan 13, 2019 18:23

I have 7zip here, though admittedly a quite old version. But as yet it was no problem.
grindstone
Posts: 637
Joined: May 05, 2015 5:35
Location: Germany

Re: Where to put keyboard code

Postby grindstone » Jan 13, 2019 18:28

Alright, downloaded and installed the latest version of 7zip, now it works.

EDIT: Is it correct that the folder "ssddata" is empty?
Last edited by grindstone on Jan 13, 2019 18:31, edited 1 time in total.
badidea
Posts: 1182
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Where to put keyboard code

Postby badidea » Jan 13, 2019 18:30

Unpacks ok here.
dodicat
Posts: 5563
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Where to put keyboard code

Postby dodicat » Jan 13, 2019 18:51

ssddata is empty.
I took the unpacked file to Linux, ssd.c compiled straight off,( I compiled to .o)
Gablea
Posts: 1037
Joined: Apr 06, 2010 0:05
Location: Northampton, United Kingdom
Contact:

Re: Where to put keyboard code

Postby Gablea » Jan 13, 2019 20:13

yea that folder is empty

I was trying to get it to work on a Windows OS but I Like to have this now only on Linux (as I would be moving to that at some point in the near future)

My Plan is to fully move my applications over to linux but one of them talks to a web interface and it uses html basic attenuation and I can not see any where how I would do this.


Its gotten to a point where i would PAY Someone to convert the card interface module to FreeBASIC (at the moment it is in VB.net)

Return to “General”

Who is online

Users browsing this forum: No registered users and 4 guests