Screen functions

New to FreeBASIC? Post your questions here.
Post Reply
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Screen functions

Post by Dinosaur »

Hi All

As some of you may know, my FB graphics are usually handled by CGUI.
But recently I have been developing applications for headless operation in Linux.
As I have not used Screen functions since my QB days, I am a beginner on this now.

Worth noting that this script below works perfectly for a cgui (Allegro) graphic program.
When the Beaglebone boots it uses .xinitrc which has the following lines for my program.

Code: Select all

#!/bin/sh

## Program restarts unless:
## If program returns an Error code of  254, it will exit and start openbox session.
## If program returns an Error code of  131, it will reboot the computer.
## If program returns an error code of  130, it will shut down the computer.
## If program returns an error code of      0, it will restar to a max of 5 times.
## Otherwise write Date & Error code to file

sleep 25
for I in 1 2 3 4 5
do
	sudo nmcli device wifi connect "TP-Link_CE38" password "********"
	sudo -u debian openbox-session &
        sudo -u debian /home/debian/Client
        STATUS=$?
##----------------------------
if test $STATUS -eq 254
  then
        sudo -u debian openbox-session

  elif test $STATUS -eq 131
   then
	sleep 30
        sudo reboot

  elif test $STATUS -eq 130
   then
        sudo shutdown now

 elif test $STATUS -eq 0
  then
	echo " `date ` exit code $STATUS " >> /home/debian/Errors.txt
	sleep 10
fi
##---------------------------
done

## Startx to allow Geany etc.
sudo -u debian openbox-session

First Lines in the program are:

Code: Select all

    Screen 19,8,1
This does not use the full screen.Other than some init routines the first print statements are:

Code: Select all

    If Debug.PrintFlag Then
        Locate 2,1:Print "Last Compiled on: " + __Time__
        Locate 3,1:Print Times.Datum;";";Times.Tyd
        Locate 4,1:Print "Press [Esc] to Quit"
        Locate 5,1:Print "-------------,----------,----------,---------,--------"
        Locate 6,1:Print "Location     , Tag Code#,   Date   ,  Time   , Tx Len."
        Locate 7,1:Print "-------------,----------,----------,---------,--------"
        Locate 8,1
    EndIf
This prints correctly on the designated screen.
Because the program relies on a scanner dumping characters in to the keyboard buffer, I use this statement to position
the mouse cursor within my window.

Code: Select all

        Dim as String Cmnd = "sudo xdotool mousemove 100 100"
        Shell Cmnd
However the problem is that the keyboard does not appear to be "linked" to that window.
If I right click in the remaining background window, I can start Geany and the keyboard works correctly.
I can run the program from Geany and it will work correctly.
Removing the screen and the keyboard still alows the program to run correctly, but scanning a Tag does not produce
any char's.

For the keyboard to be linked to an open window, what are the conditions that must be satisfied.?
No amount of reading and browsing over the last two days has resolved this.

Would love to hear any suggestions that might resolve this.

Regards
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Screen functions

Post by badidea »

Hi Dinosaur, trying out the xdotool here.

I run in one terminal this:

Code: Select all

sleep 5; xdotool key "A" "B"
While this freebasic program is running:

Code: Select all

screen 19,8,1
dim as string key
while key <> chr(27)
	key = inkey
	if key <> "" then print "Got:" & key
wend
And it does work as expected (Got:A, Got:B). The freebasic (graphics) screen needs to be selected, else the keystrokes go to some other process. So select within the delay of 5 seconds.

I read in the manpages that you can also specify a window id. But I do not know how to use that.
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: Screen functions

Post by Dinosaur »

Hi All

badidea, thanks for the reply.

I "Ass"umed that when a window is created and no other process started after it, that it would have the focus.
Turns out it didn't, I had to click in the title bar to achieve that.(hard to do in a headless system)
So, added a line:
sudo xdotool click 1
and positioned the mouse at 5,100 (on Title bar)
Basically left clicks mouse once, the 1 indicates left button.

The manual states:
Xterm automatically highlights the text cursor when the pointer enters the window (selected) and unhighlights it when the pointer leaves the window (unselected).
Not in my experience, you have to click it before it is selected. After that first time, then that statement is correct.

Interesting that FB does not have any "dummy" Mouse or Key input functions. I can do this with Allegro when using cgui.
-e program [ arguments ... ]
This option specifies the program (and its command line arguments) to be run in the xterm window. It also sets the window title and icon name to be the basename of the program being executed if neither -T nor -n are given on the command line. This must be the last option on the command line.
There is no -n or -T in the manual.So again it should have named the Window "Client" as I did not specify -T or -n.

Will experiment some more and update if I resolve all the minor issues.

Regards
Post Reply