05-23-2024, 04:26 AM
(This post was last modified: 05-23-2024, 04:26 AM by DSMan195276.)
I would agree that the file input like that is likely to cause problems, files really aren't made for that kind of task. Your best QB64 option would be a TCP/IP connection between the two programs, which overall is fairly easy to implement. If you have the main program start the mouse program then you can even pass the connection details as an argument to avoid hard-coding them between the programs.
I have two simple examples here, the `host` would be your main program and the `client` would be the mouse program:
Host:
Client:
You probably already deal with this with the files, but one thing to note is that there's no guarantee on the batching of the bytes sent by the other program. You'll see this if you run my example programs, sometimes the Host receives multiple lines of input and sometimes only one. Effectively the best approach is to simply buffer up all the `Get` strings until you have enough bytes to have a full mouse message, rather than expect to receive whole mouse events one at a time.
Using a "pipe" is another option, but those aren't exposed in QB64 so it would be a bit more complex.
I have two simple examples here, the `host` would be your main program and the `client` would be the mouse program:
Host:
Code: (Select All)
Dim port As _Unsigned Integer
' between 40000 and 50000
port = Rnd * 10000 + 40000
h& = _OpenHost("tcp/ip:" + _Trim$(Str$(port)))
Print h&
Shell _DontWait "client " + Str$(port)
c& = 0
While c& = 0
_Limit 60
c& = _OpenConnection(h&)
Wend
Do
_Limit 60
'main loop
Get #c&, , s$
Print s$
Loop While _Connected(c&)
Client:
Code: (Select All)
Dim port As _Unsigned Integer
port = Val(Command$(1))
Print "port: "; port
c& = _OpenClient("tcp/ip:" + _Trim$(Str$(port)) + ":localhost")
Print c&
Do
_Limit 120
' send mouse info
i = i + 1
s$ = "hi there! " + Str$(i)
Put #c&, , s$
Loop
You probably already deal with this with the files, but one thing to note is that there's no guarantee on the batching of the bytes sent by the other program. You'll see this if you run my example programs, sometimes the Host receives multiple lines of input and sometimes only one. Effectively the best approach is to simply buffer up all the `Get` strings until you have enough bytes to have a full mouse message, rather than expect to receive whole mouse events one at a time.
Using a "pipe" is another option, but those aren't exposed in QB64 so it would be a bit more complex.