LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Send keyboard commands to another windows program

Hello all,
I would like to send keyboard commands to a windows program from my Labview code. The idea is, this Windows program is a stand-alone program for image acquisition and we have to interact with it manually for grabbing image, giving filename and saving it etc. Another Labview program does some machine control. We want to launch the Windows Imaging program, then start the Labview program and at appropriate states, the Labview program will send keyboard commands to the imaging program to make this an automated sequence.
 
To the best of my knowledge, the imaging program does not support DDE. I have written a small VB program (just to test) to send keyboard commands to the imaging program and it works perfectly. But my goal is to do this from Labview.
 
I will apprciate any help.
 
Thanks in advance.
0 Kudos
Message 1 of 17
(10,938 Views)

How are you doing it from the VB program? If there isn't a similar method in LabVIEW a fall back position might be to create a ActiveX control using VB that could be used from within LabVIEW. The usual methods, such as talking to Excel or Word, require them to have ActiveX connectivity. DDE, which you already mentioned it doesn't have support for, would usually be the alternative. Connecting from the VB program shows some means of connectivity, so all isn't lost yet. Have you browsed the "Help/ Find Examples/Communicating with External Applications"?

 

P.M.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 17
(10,915 Views)

I have used the Sendkey() method in VB to send keyboard commands - this however requires that the imaging app window has focus.

The imaging app was not written by me so I am not sure how I can turn it into an ActiveX container. I just have an exe file.

I looked through the examples. Nothing jumps at me..

I searched around and found some gtoolbox advertises similar functionality. I did not download as it is not free but thought I would ask this community if anyone has had success with such toolbox.

Thanks again.

~Roy

0 Kudos
Message 3 of 17
(10,907 Views)

Simulating keyboard clicks by calling the windows API SetKeyboardState or KeybdEvent functions is fairly easy. You can find some examples if you search the forums. The trick is that the field or window has to have the focus. Another option is probably sending windows messages to the application window, but I haven't tried that path myself.

You can look at the integrating DLLs part of this site for information about calling DLLs and you can find documentation on windows function on the MSDN site.


___________________
Try to take over the world!
0 Kudos
Message 4 of 17
(10,900 Views)
Hi,


The suggested method SendKey work, but fail when the application is not the active window. I don't think SetKeyboardState will work, because (from MS SDK): "Changes made to this table do not affect keyboard input to any other thread.".


A failsafe method is a bit more difficult. First, you need a window handler of the program's window. There can be more then one, and some might be created by the program on the fly. You can search all windows with window api's such as FindWindowEx etc.


Once you have a hWindow, you can send messages to it using SendMessage, SendMessageTimeout or SendNotifyMessage . This way the program receives keyboard messages just like when they where send by windows. You can even send menu selection, window close events etc, but it's not trivial.


An alternative method is to use SetWindowsHookEx to set a keyboardproc, but that is a bit difficult.


Regards,


Wiebe.



"Biomed_developer" <x@no.email> wrote in message news:1141053046270-330670@exchange.ni.com...
Hello all,
I would like to send keyboard commands to a windows program from my Labview code. The idea is, this Windows program is a stand-alone program for image acquisition and we have to interact with it manually for grabbing image, giving filename and saving it etc. Another Labview program does some machine control. We want to launch the Windows Imaging program, then start the Labview program and at appropriate states, the Labview program will send keyboard commands to the imaging program to make this an automated sequence.
&nbsp;
To the best of my knowledge, the imaging program does not support DDE. I have written a small VB program (just to test)&nbsp;to send keyboard commands to the imaging program and it works perfectly. But my goal is to do this from Labview.
&nbsp;
I will apprciate any help.
&nbsp;
Thanks in advance.
0 Kudos
Message 5 of 17
(10,894 Views)


wiebe@CARYA wrote:
I don't think SetKeyboardState will work, because (from MS SDK): "Changes made to this table do not affect keyboard input to any other thread.".

Now I remember why I used KeybdEvent and not this when I wanted to simulate key presses. Smiley Happy

___________________
Try to take over the world!
0 Kudos
Message 6 of 17
(10,894 Views)
Thanks Wiebe. I would like to try your suggested method. Do you know of example codes floating around on this forum or elsewhere? For example, do these calls like FindWindowEx, SendMessage etc. part of a vi library?
 
~Roy
0 Kudos
Message 7 of 17
(10,884 Views)
There were some examples floating around. Try searching for "LV toolbox", "winutil32" or labuseful's VIs.

___________________
Try to take over the world!
0 Kudos
Message 8 of 17
(10,873 Views)
Roy,


I think OpenG has some code for finding windows, but I always rewrite my own (after rewriting it 20-30 times, it's faster to make then looking up the url for OpenG).


I'll see if I can post something tomorrow (GMT+1)..


Regards,


Wiebe.


"Biomed_developer" <x@no.email> wrote in message news:1141137643801-331241@exchange.ni.com...
Thanks Wiebe. I would like to try your suggested method. Do you know of example codes floating around on this forum or elsewhere? For example, do these calls like FindWindowEx, SendMessage etc. part of a vi library?
&nbsp;
~Roy
0 Kudos
Message 9 of 17
(10,872 Views)

Hi Wiebe,

Thanks for your help. Were you able to find some example that you could post?

~Roy

0 Kudos
Message 10 of 17
(10,853 Views)