Jump to content
The simFlight Network Forums
ammarmalhas

Sending keyboard key combination to Explorer on local PC, launch batch files

Recommended Posts

54

Dear Pete and others who may know the answer,

First off, apologies if this had been addressed before but a search through the forum did not reveal what i was looking for.

I need to send a keyboard combination to the explorer on the same PC where FSUIPC is running when I press a hardware button.

I have found many topics about using WideFS for sending key combos to another PC (which i may be using later).

How do I send the keys to the local PC and the Explorer (desktop)?

AND is there a way to launch a batch file with an FSUIPS button press?

Many thanks.

Ammar

Share this post


Link to post
Share on other sites

I need to send a keyboard combination to the explorer on the same PC where FSUIPC is running when I press a hardware button.

I have found many topics about using WideFS for sending key combos to another PC (which i may be using later).

How do I send the keys to the local PC and the Explorer (desktop)?

AND is there a way to launch a batch file with an FSUIPS button press?

 

Both things can be done with Lua plug-ins, which you can then assign to your buttons. They are dealt with in the ext library (ext for "external").

 

For sending a keypress to a program external to FS use the ext.sendkeys function.

 

For starting a batch file use the ext.shell function.

 

Pete

Share this post


Link to post
Share on other sites

Thank you, where can I read more about LUA and how to actually use it with FSUIPC!, I have no idea what LUA is. :oops:

 

See the stuff in the FSUIPC Documents subfolder. in your FS Modules folder. Did you not even read the Installation document packaged with the FSUIPC installer which tells you what is installed and where?

 

Pete

Share this post


Link to post
Share on other sites

Well SIR, like almost 99.99% of MAC users (I mainly use MAC for my work and the PC only for my sim) I am used to programs being self-explanatory and easy to follow with similar logic and consistent flow throughout all programs from different vendors, HENCE I did not and do not make it a habit to READ documentations and hundreds of pages just to figure out how things are done in an application!

Indeed in the FSUIPC documentation folder i find "FSUIPC Lua Library" and "FSUIPC Lua Plug-Ins". NOW, I realize, after two years of installing FSUIPC, that the second file explains some things about what Lua is and how it works with FSUIPC.

I had never bothered to read anything about Lua nor would I have done if you guys here had not mentioned it!

Lua ...! Sounds like a license-read-me file thing!

I will read it before I bother again!

Share this post


Link to post
Share on other sites

Hi Pete, where can I read about the syntax of Lua "ext.sendkeys(handle, ...)"  ? What is "..."  ? How to enter Keycodes?

I didn't find on Page 17 of EXT Libray manual.

Another question:  I started an AddOn and I got the "handle". Can I use it as a public variable in my Lua with "ext.sendkeys" ?

How works the assignment to an application in more than one Lua script? I think "handle" is the reference ?

thanks

  Alhard

Share this post


Link to post
Share on other sites
4 minutes ago, alihor said:

Hi Pete, where can I read about the syntax of Lua "ext.sendkeys(handle, ...)"  ? What is "..."  ? How to enter Keycodes?

If the Lua library documnet, in your FSUIPC Documents folder.

The ... part is explained there, of course.

7 minutes ago, alihor said:

I didn't find on Page 17 of EXT Libray manual.

Why not follow on with the continuation on psge 18 then?

8 minutes ago, alihor said:

Another question:  I started an AddOn and I got the "handle". Can I use it as a public variable in my Lua with "ext.sendkeys" ?

The Handle must have been obtained in the Lua plug-in using any of the methods defined for obtaining a program handle. in the EXT library. (It is actually a Window handle, which should be the main program Window).

11 minutes ago, alihor said:

How works the assignment to an application in more than one Lua script? I think "handle" is the reference ?

I'm not sure off-hand whether Handle is local to the particular Lua plug-in, or can be passed over using ipc.Set and ipc.Get. You'll need to try it.

Pete

 

Share this post


Link to post
Share on other sites

:oops:   Hi Pete, thank you for get me reading the next page. It was late ....

Now I could create two Lua plug-ins, which are called by FSUIPC buttons. But they didn't work. The ext.sendkeys did not send the text string.

During last days, I tested and tested with different and changed Lua scripts.

Then I found finally the reason why my script was not working : the question now is

        Why are my two test handles different ? (see my attached scripts)

First I start by button the script "ahCallFC.lua" then after Notepad started I start by another button "ahZoomIn.lua"

The script only works perfect when the handle is created in second script "ahZoomIn.lu".

The ipc.set and ipc.get create different handles.

Both Lua scripts are attached.

WIN7-64 PRO ,  FSUIPC Version : 4.974,  FSX SP2

Please help , as ever. Thanks

Alhard

ahCallFC.lua

ahZoomIn.lua

Share this post


Link to post
Share on other sites
8 minutes ago, alihor said:

Then I found finally the reason why my script was not working : the question now is

        Why are my two test handles different ? (see my attached scripts)

The handle is generated in the thread. It is an index to a table of actual Window handles, it isn't the actual Window handle. The scripts do different things. One gets a handle from ext.run, the other by finding a Window with a given name or title. These aren't compared to see if they are the same thing. Each will use a slot in the handle table, that's all.

11 minutes ago, alihor said:

The ipc.set and ipc.get create different handles.

Looking at your code, you aren't comparing those. And you are using the same name for one of your handles as for the Global Name.   That is confusing things for you to start with.

But your code contains:

FC_window = ext.gethandle("notepad.exe")
x2 = FC_window
-----------------------------------------------------------------------------    
x = ipc.get("FC_window")    -- get Global Variable "FC_window"
----------------------------------------------------------------------------
----  WHY ARE THE HANDLES X and X2 DIFFERENT ??????????????? ------

and the reason for that is ipc.gethandle is getting you a local handle, not the global one obtained by the ext.run in the other thread.  Why would you think they'd be the same?

If you are going to get a local handle, use that. Why mess with global ones?

(BTW there may be more than one copy on Notepad.exe running at the same time. I don't think there's anything stopping it)

Pete

 

Share this post


Link to post
Share on other sites

Good morning Pete,

I was so surprised to get a response within 5 minutes. Two hours after midnight!  Great! Thank you.

You are obviously also a late night worker, or better : an early morning worker. ( is there a special english term ?)

8 hours ago, Pete Dowson said:

If you are going to get a local handle, use that. Why mess with global ones?

The reason for having global variables (handles) is, that I want to create different Lua scripts for different FSUIPC buttons, all referring to the one application started with "ex.run" when starting FSX. My thinking is: in this case I must NOT always run the "ipc.get" with the application name. If the application name changes, I have to rename this name  in all the Lua scripts.

Maybe there is a better solution. I am thinking of transfering a button parameter by ipcPARAM within just ONE Lua script.

9 hours ago, Pete Dowson said:

(BTW there may be more than one copy on Notepad.exe running at the same time. I don't think there's anything stopping it)

I stopped always the Notepad manually before starting a new testrun.

Can you please send me an example for usage of ipc.set  /  ipc.get  ?

have a good day

Alhard

 

 

Share this post


Link to post
Share on other sites
2 hours ago, alihor said:

The reason for having global variables (handles) is, that I want to create different Lua scripts for different FSUIPC buttons, all referring to the one application started with "ex.run" when starting FSX.

Okay, so do that. In the example you sent me you were getting another handle in the 2nd plug-in, using ext.gethandle. Why do that? Just use the one in the global.

2 hours ago, alihor said:

My thinking is: in this case I must NOT always run the "ipc.get" with the application name. If the application name changes, I have to rename this name  in all the Lua scripts.

The name you save a global variable as  is not relevant to anything. You can call it "elephant" or, more sensibly, "myhandle". Where is your thinking that the name is important?  It is only a label.

2 hours ago, alihor said:

Can you please send me an example for usage of ipc.set  /  ipc.get  ?

An examples? There's nothing to it!

In one plug-in, ipc.set("elephant", handle)
in the other, started later or from within the first, handle = ipc.get("elephant")

Pete

 

Share this post


Link to post
Share on other sites

Hi Pete, here I am again, very desperate .

I changed the script in one script only (see attachments).

This script (ahFC_Control) should control remotely by Lua my AddOn "FS-FlightControl".

As this script doesn't work properly I created a second copy (ahNP_Control), just with another application call , the NOTEPAD.

In the scripts I commented what is not working. The LOGs didn't give me information about these errors.

Do you have an idea how to get it working? What can I do additionally for debugging?

Add Info: All Key entries work manually with the AddOn perfect !!

Alhard

ahFC_Control.lua

ahNP_Control.lua

Edited by alihor
Additional Info

Share this post


Link to post
Share on other sites
52 minutes ago, alihor said:

In the scripts I commented what is not working.

The only one in the "np" file is:

ext.state(myHandle,EXT_MAX)      ----  does NOT work

Maybe it needs the focus BEFORE it accepts the "Maximise" message, though it shouldn't.  Anyway, does it "not work" in both cases -- when Notepad is already running as well as when you just loaded it a few lines earlier? Maybe you need that sleep beforehand too, to give it time to be established first.

In the other one you found that the sendkeys isn't working either.  This may be a result of the program, FS-FlightControl,  not processing keys in the way that the Lua functions send them.  Quite a few programs process keyboards directly rather than use the standard Window messages.

However, the main reason looks to be this:

        ext.focus(myHandle)                  -- not working

If it doesn't have the focus it probably won't process the keypresses in any case.

I use FS-FlightControl, and when started it takes a long time before it is actually ready.  Assuming there is no update it takes over 10 seconds here even on a fast system. There's a couple of seconds before it loads its starting window, which isn't one which will accept any messages in any case. Then another 8 seconds at least before it reaches its normal screen.

BTW why are you using "ext.run" in the one case but "ext.shell" in the other? Note the description of the ext.state function:

"This does its level best to make the identified program the
current foreground program, receiving keystrokes and mouse
clicks.
The program must be one started by ext.run or
ext.runif."

I don't think it can get the proper Window handle for Shelled programs -- shell also does things like run batch files and execute other system functions. it isn't specifically program oriented.

Pete

 

 

 

Share this post


Link to post
Share on other sites

Hi Pete,

4 hours ago, Pete Dowson said:

In the other one you found that the sendkeys isn't working either.  This may be a result of the program, FS-FlightControl,  not processing keys in the way that the Lua functions send them.  Quite a few programs process keyboards directly rather than use the standard Window messages.

I will talk to Andreas. I am one of his beta testers since two years.

4 hours ago, Pete Dowson said:

I use FS-FlightControl, and when started it takes a long time before it is actually ready.  Assuming there is no update it takes over 10 seconds here even on a fast system. There's a couple of seconds before it loads its starting window, which isn't one which will accept any messages in any case. Then another 8 seconds at least before it reaches its normal screen.

Therefore I inserted a sleep for 15 secs in the FC script, as you can see. Maybe too short.

4 hours ago, Pete Dowson said:

BTW why are you using "ext.run" in the one case but "ext.shell" in the other? Note the description of the ext.state function:

Yes it's changed already to "run". This was an elder version. Sorry.

So your result is: it should work locally also. I tested FS-FlightControl on a remote PC with WideClient and there it works. Why?

Is the "KeySend" for WideFS in FSUIPC different to "ext.sendkeys" in Lua ?

Alhard (drinking a glas of red wine on your health)

Share this post


Link to post
Share on other sites
1 hour ago, alihor said:

Therefore I inserted a sleep for 15 secs in the FC script, as you can see. Maybe too short.

Possibly it's using the handle from the ext.run, because that may be getting the initial Window handle, not the eventual one. Though I'm not sure about that. might be worth using GetHandle after your delay instead.

1 hour ago, alihor said:

So your result is: it should work locally also. I tested FS-FlightControl on a remote PC with WideClient and there it works. Why?

That's very odd as the code in Wideclient is identical to that in FSUIPC. All of the Lua stuff is, except where parts are only applicable to one or the other.

1 hour ago, alihor said:

Is the "KeySend" for WideFS in FSUIPC different to "ext.sendkeys" in Lua ?

Oh, you don't mean the Lua then!?

The KeySend for keypresses has a variety of methods applicable, according to parameters. Please see the WideFS technical document.

Pete

 

Share this post


Link to post
Share on other sites

Hi Pete, I followed you proposal, no success.

On 9.3.2018 at 12:14 AM, Pete Dowson said:

Possibly it's using the handle from the ext.run, because that may be getting the initial Window handle, not the eventual one. Though I'm not sure about that. might be worth using GetHandle after your delay instead.

I tested again all my test functions in FS-FlightControl remote with WideClient, AND IT WORKS.

Here ist my WideClient.INI extract :

[User]
Log=Yes
UseSendInput=Yes
;....
KeySend10=187,12, Run1; Alt - +  Zoom +
KeySend11=189,12, Run1; Alt - -  Zoom -
KeySend12=90,12,Run1; Alt - Z   Auto Zoom
KeySend13=70,11,Run1; Ctrl Sh F   Flight Plan
KeySend14=77,11,Run1; Ctrl Sh M   MAP
;....
ButtonScreen=Yes
; ===============================================
Run1=C:\Program Files\FS-FlightControl\FS-FlightControl.exe
;Run2=C:\Windows\System32\notepad.exe
;....
; ===============================================

Question 1: How can I test the SendKeys function without FSUIPC, Just as a simple Lua script ? How?

Question 2: How can I concatenate text strings with "ipc.linedisplay", line negative doesn't work ?

Attached is my current Lua script,

thanks, Alhard

ahFC_ControlV4.lua

Share this post


Link to post
Share on other sites
41 minutes ago, alihor said:

I tested again all my test functions in FS-FlightControl remote with WideClient, AND IT WORKS.

What is "FS-FlightControl remote"? I use FS-FlightControl and I don't think I've come across a different version.

43 minutes ago, alihor said:

KeySend10=187,12, Run1; Alt - +  Zoom +
KeySend11=189,12, Run1; Alt - -  Zoom -
KeySend12=90,12,Run1; Alt - Z   Auto Zoom
KeySend13=70,11,Run1; Ctrl Sh F   Flight Plan
KeySend14=77,11,Run1; Ctrl Sh M   MAP

Actually I didn't even realise there were keyboard shortcuts for FS-FlightControl facilities. I'll have to check into the documentation more!

44 minutes ago, alihor said:

Question 1: How can I test the SendKeys function without FSUIPC, Just as a simple Lua script ? How?

SendKeys is only used by FSUIPC. It's an encoded message sent to the client like any other Sim information. Unless you write a program to link to WideClient in the same way FSUIPC does, using the same (undocumented) protocol and the apropriate Network code, you cannot instigate them without the link to FSUIPC. I don't understand why you'd want to in any case.

46 minutes ago, alihor said:

Question 2: How can I concatenate text strings with "ipc.linedisplay", line negative doesn't work ?

What is "line negative"?

You need to concatenate the text before sending.  FSUIPC is simply calling on a SimConnect function to display the text. There's no way to amend something already sent. It's out of FSUIPC's control by then. You'd need to replace it.

50 minutes ago, alihor said:

Attached is my current Lua script

Do I need that for something?

Pete

 

Share this post


Link to post
Share on other sites
52 minutes ago, Pete Dowson said:

What is "FS-FlightControl remote"? I use FS-FlightControl and I don't think I've come across a different version.

Actually I didn't even realise there were keyboard shortcuts for FS-FlightControl facilities. I'll have to check into the documentation more!

I run my simulator with two PCs. One is the Master with FSX and the second PC is the Client for AddOns.
On the second PC I run FS-FlightControl (FC) started by WideClient (script inserted before).
Now I want to control FC via buttons and FSUIPC on the Master PC.
FC could be controlled by Shortcuts:
Link    main-menu-buttons
    Keyboard Shortcuts
    All main menu buttons can also be access by keyboard shortcuts.
    Just keep the keys CTRL and SHIFT pressed and then add one of the following keys for the corresponding module or action button:
    Key     Module or Action
    P         Position
    M         Map
    F         Flight Plan
    etc.
    Also all underlined letters in the function boxes of FC can be called by shortcut "Alt - letter".

This works pretty good via WideClient !!

Now I want also to control FC locally on the FSX PC. There I am stuck.

56 minutes ago, Pete Dowson said:

SendKeys is only used by FSUIPC. It's an encoded message sent to the client like any other Sim information. Unless you write a program to link to WideClient in the same way FSUIPC does, using the same (undocumented) protocol and the apropriate Network code, you cannot instigate them without the link to FSUIPC. I don't understand why you'd want to in any case

Cause my scripts failed, I want to go another way to TEST sending keys to the local FC. Or can I even use WideClient locally ? I think NO.

58 minutes ago, Pete Dowson said:

What is "line negative"?

Lua Library.pdf page 4:
 line < 0
 Adds this text as another line in the list, following
the last one sent. The line parameter gives the
negative of the maximum line number to be used
(counting from 1, max 32), and if this line would
be placed there, the display is scrolled up one line
before it is added.

Misunderstanding by me.

1 hour ago, Pete Dowson said:

Do I need that for something?

No you don't. Just for info.

 

Now I will continue finding the failure in my script or in the combination of my system.

Alhard

Share this post


Link to post
Share on other sites
21 minutes ago, alihor said:

I run my simulator with two PCs

Yes, mine has 8 PCs!

* One for P3D4 and ProSim main and MCP, and ASP4,
* one for ATC and ProsimUtils,
* One for the EFB (FS-FlightControl now, used to be Aivlasoft's EFB),
* two: one each for the two CDUs
* one for the main PFD displays,
* one for the EICAS display
* one for PFPX and TopCat, and for monitoring the cockpit from downstairs in my office

Apart from on the EFB (a touchscreen inside the cockpit) I have two other licensed installs of FS Flight-Control, as well as a "trial" one, unused, on the P3D PC just to generate the data it needs from the correct scenery files.

28 minutes ago, alihor said:

FC could be controlled by Shortcuts:
Link    main-menu-buttons

Ah. I really MUST read documentation properly! I keep exhorting my own users to read the stuff I supply! (Do as I say, not as I do! ;-))

30 minutes ago, alihor said:

Now I want also to control FC locally on the FSX PC. There I am stuck.

Ah, that's a different matter.

Tell me, does the remote copy have focus when you use these "SendKeys" assignments?

If you need it to have focus on the FS PC, then FS will lose that focus. That could result in a loss of FS sound and a slow down (less frames per second).

32 minutes ago, alihor said:

Cause my scripts failed, I want to go another way to TEST sending keys to the local FC. Or can I even use WideClient locally ? I think NO.

Yes, you can. You need to change the ClassInstance parameter in the WideClient.INI file to something other than 0 (1 will do).

37 minutes ago, alihor said:

Lua Library.pdf page 4:
 line < 0
 Adds this text as another line in the list,

Yes, another line. To overwrite an earlier line you use line > 0, and erase those below ready to rewrite.

38 minutes ago, alihor said:

Misunderstanding by me.

Okay.

If I get time I will try your Lua script on my est PC, where I can run both P3D4 and FS-FlightControl at the same time.

Pete

 

Share this post


Link to post
Share on other sites

Great, that you try to test my script.

I will check your Focus question   asap.

If WideClient runs locally, , how can I distiguish between the remote WideClient and the local when using WideFS(sendkey) in FSUIPC?

Regards 

Alhard

 

Share this post


Link to post
Share on other sites
4 hours ago, alihor said:

If WideClient runs locally, , how can I distiguish between the remote WideClient and the local when using WideFS(sendkey) in FSUIPC?

You'll need to use different SendKey numbers (the parameter in the assignment and the number on the left in the Wideclient.INI preceding the =). you do have 255 to choose from!

Pete

 

Share this post


Link to post
Share on other sites

I tried your Lua program with FS-FlightControl, and I managed to make some improvements to the way FSUIPC gets hold of the Window handles.

As far as I can find from all my testing here, your Lua now works -- except of course where you have mistakenly used "postmessage" instead of "postkeys". The message one needs full details of which message and its parameters. It is for programmers.

Instead of starting FS_flightcontrol  and having a fixed delay (which isn't long enough here unless it has been loaded before in this Windows sessio), you should use a loop, perhaps checking once per second, with an included sleep of just 1000 (1 sec), and have a fail exit after, say, 20 or 30 loops.

I will release an interim update with the fix, probably tomorrow -- but possibly not till Wednesday, as I have folks here dealing with other things. Anyway, look out for an update in the Download Links subforum over the next few days.

Pete

 

 

Share this post


Link to post
Share on other sites
17 minutes ago, Pete Dowson said:

I tried your Lua program with FS-FlightControl, and I managed to make some improvements to the way FSUIPC gets hold of the Window handles.

As far as I can find from all my testing here, your Lua now works -- except of course where you have mistakenly used "postmessage" instead of "postkeys". The message one needs full details of which message and its parameters. It is for programmers.

I AM EXCITED! Thanks. I will wait patiently for your update.

"postmessage" was just for desperate testing. I will replace.

I admire your dedication for us Simmers !

regards

  Alhard

Share this post


Link to post
Share on other sites

The updates are completed and available in the Download Links subfolder. Look for

WideClient 7.141
FSUIPC 4.974a
FSUIPC 5.124a

as appropriate to your needs.

Pete

 

Share this post


Link to post
Share on other sites

Hi Pete, I am sorry, but it doesn't work, unfortunately.

Attached is my Lua file and the LOG file.

My systems run WIN7-64 PRO, could this influence the behaviour?

Btw:  Who calls this ipcDebug ?

*** LUA Error: cannot open Z:\FSX\Modules\ipcDebug.lua: No such file or directory

Alhard

ahFC_Control.log

ahFC_Control.lua

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.