LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to send data to active process from labview ( like key board does)

Hi everyone,

i will begin by explaining my purpose

we all know that the key board is able to write to any selected process (like google, word , text file...).

how can i do this with LabVIEW?

How To detect the active process and send a string to it ?

i appreciate your help 

thanks

0 Kudos
Message 1 of 11
(3,707 Views)

A vague question receives a vague answer.

 

 Use a "string control".

 

Maybe a little more information on what exactly your are trying to do would result in a more informative answer. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 11
(3,680 Views)

thaks

for example if i select a text entry field in google or any other application , the key board detect it automatically and can write on it . so the key board detect the foreground application selected by the cursor and enter information. if for example there is two word applications opened at the same time, the keyboard cannot write in both of them. it can write only in the selected one.

the windows system indicate to the keyboard the foreground application so it can enter information .

how to do the same thing with labview?

how to detect the current active windows application and write some information in it?

thanks 

 

0 Kudos
Message 3 of 11
(3,675 Views)

@mon3am wrote:

thaks

for example if i select a text entry field in google or any other application , the key board detect it automatically and can write on it . so the key board detect the foreground application selected by the cursor and enter information. if for example there is two word applications opened at the same time, the keyboard cannot write in both of them. it can write only in the selected one.

the windows system indicate to the keyboard the foreground application so it can enter information .

how to do the same thing with labview?

how to detect the current active windows application and write some information in it?

thanks 

 


Well the keyboard is going to "write to" the application that has "focus" but you have to first bring that application into the foreground or give it focus by clicking on it.

 

There are ways to make program "take focus" and put themselves into the foreground.

 

I believe there are property nodes in LabVIEW for front panel objects to select or determine if an object has focus.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 11
(3,669 Views)

It depends on the window you try to write to.

If it's MS Word, you should use ActiveX;

if LabVIEW, you should use VI Server;

if don't know the window at all, put your text onto clipboard, and then try to simulate a Ctrl-V.

To detect the current active window, use Windows API: GetActiveWindow.

 

 

 

George Zou
0 Kudos
Message 5 of 11
(3,646 Views)

@mon3am wrote:

thaks

for example if i select a text entry field in google or any other application , the key board detect it automatically and can write on it . so the key board detect the foreground application selected by the cursor and enter information. if for example there is two word applications opened at the same time, the keyboard cannot write in both of them. it can write only in the selected one.

the windows system indicate to the keyboard the foreground application so it can enter information .

how to do the same thing with labview?

how to detect the current active windows application and write some information in it?

thanks  


Technically you have it completely backwards. The keyboard knows nothing about who the current application is. Instead the keyboard driver sends keystrokes to the Windows kernel which then distributes according events to the message loop of the currently active application. So basically the Windows kernel is responsible to distribute those events as WM_.... messages, together with many many other messages. You can send messages to applications directly using the SendMessage() Windows API.

 

 

But aside that you need to interface to a Windows API through the Call Library Node, which is already kind of an advanced topic in its own, you can't just go and send random messages to other applications. The actual keyboard scan codes are usually sent to the main message of an application only, which can intercept them and process them itself or if it doesn't do so, the Windows message default handler will then translate them to character strokes that are sent to the actual window that has the key-focus. And since Windows 7 with UAC you can not send all messages to other processes as you wish, but only certain restricted messages. All the other messages are intercepted and discarded by the Windows UAC protection to prevent a process from injecting dangerous messages into other processes.

 

If you want to just simulate keyboard keys being pressed you can use the SendInput() function instead which will simulate keyboard, mouse or hardware events and send them to the kernel which will distribute them to whatever application has currently the focus.

Rolf Kalbermatter
My Blog
Message 6 of 11
(3,621 Views)

rolfk,

Do you know where I can find a list of messages blocked by UAC?

 

George

George Zou
0 Kudos
Message 7 of 11
(3,616 Views)

rolfk is right, in that you're going to need to get dirty with the Windows API to do what you you're asking from LabVIEW. That said, if you aren't tied to LabVIEW you might consider AutoHotKey or AutoIt. Both of these programs can send keyboard and mouse inputs to a specified window, and in some cases a specified control.




Certified LabVIEW Architect
Unless otherwise stated, all code snippets and examples provided
by me are "as is", and are free to use and modify without attribution.
0 Kudos
Message 8 of 11
(3,595 Views)

@zou wrote:

rolfk,

Do you know where I can find a list of messages blocked by UAC?

 


Sorry for using the wrong acronym. The right one is called User Interface Protection Isolation (UIPI) and it does work slightly different than what I indicated in my first post. User applciations are assigned protection levels. An application can only send messages to another application of the same or lower level unless a higher level application explicitly enabled sending of certain messages from any application by using the ChangeWindowsMessageFilter() API.

SendMessage() and PostMessage() will report success but drop the message silently when you attempt to send a message to a higher level application that hasn't enabled sending of that specific message. 

Rolf Kalbermatter
My Blog
Message 9 of 11
(3,587 Views)

Here is a potential hack around:

 

Send the data out to a serial port that is wired to another port to receive the data.

Then purchase a software keyboard wedge package that is set up for the receiving port to parse the data and it will direct it to the application as if it was typed in by the keyboard.

 

-AK2DM

~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 Kudos
Message 10 of 11
(3,567 Views)