Discussion:
keybd_event for dos application
(too old to reply)
TheStig
2008-08-07 19:10:06 UTC
Permalink
I have a dos application that I am trying to control with keybd_event. I have executed and operated external applications in a loop in the past but I cannot seem to pass any keys to this particular application. Attached are the vi and the executable. You will have to change the working and exe path to see an example of my problem. Any assistance is greatly appreciated.


BBLIST.zip:
http://forums.ni.com/attachments/ni/170/347638/1/BBLIST.zip
smercurio_fc
2008-08-07 21:10:06 UTC
Permalink
I'm not quite sure what you're doing with that loop there. What are you trying to send? It seems that the stuff to send is based on the directory listing of "C:\bin_to_text", which we don't have.
TheStig
2008-08-07 22:10:07 UTC
Permalink
What I have is approximately 9000 binary files in the bin_to_txt folder. The vi opens the dos application (BBlist.exe) and sends each of the 9000 file names to the dos application in sequence by sending keyboard strokes.

 

For example, if you were to manually open the BBList program the first thing it asks for is the file name. Therefore, the vi enters the file name one letter at a time as if you were doing so from the keyboard. The outer loop runs once for every file, the inner loop runs once for every keyboard stroke.

 

1. To test the program put BBLIST in your root folder c:

 

2. Make a dummy folder called bin_to_text in your root folder c:\bin_to_text\

 

3. Save a text file of any name you like and put it in the bin_to_text folder

 

4.  Run the VI.

 

The VI should open BBList but nothing else will happen. If it were to work as intended you would see the text file name in the input field.

 

The way the vi works is by passing keystrokes to the active application which is the BBList at the time. To check if the keystrokes are working just maximise a text document right after BBlist opens. The text document will be the active application and you will see the name of the text file you created typed out.

 

Thanks for the reply, I didn't think this would get any attention.
 
 
 
 
mikeporter
2008-08-08 03:10:06 UTC
Permalink
According to the documentation from RDI, it sounds like the program you really need to be using is their batch conversion program BBBATCH. (Page 19 of the RDI Tool Users Guide - available as a pdf file <a href="http://www.comm-tec.com/Prods/mfgs/RDI/Software/Manuals/RDI-Tools-Manual/RDI%20Tools%20User%20Guide.pdf" target="_blank">here</a>.) Mike...
TheStig
2008-08-08 13:40:08 UTC
Permalink
Mike,
I have looked into that route and I am working on a solution with Teledyne. BBBATCH does not work correctly. They have recomended an alternative that I'm looking into.
&nbsp;
smercurio_fc
2008-08-08 14:40:09 UTC
Permalink
I don't quite understand what keys you're tyring to send prior to the filenames. I would think you just want to send 3 backspaces, but that's not what it seems that you are doing. I used <a href="http://www.autoitscript.com/autoit3/" target="_blank">AutoIt</a> to implement an alternate solution which is much cleaner. I've attached it if you're interested in seeing it. I only took it as far as entering a single filename, as I have no idea how the program is supposed to be used.


BBList AutoIt Example.vi:
http://forums.ni.com/attachments/ni/170/347876/1/BBList AutoIt Example.vi
TheStig
2008-08-08 15:10:13 UTC
Permalink
smercurio,

&nbsp;

I get an error on the "automation open". Are you able to pass a string to the application?

&nbsp;

The three backspaces are not required.&nbsp;Hit any letter and it overwrites the default&nbsp;*.* . The keys you see in the cluster array are random. I stopped at that point because it was obviously not working correctly.
&nbsp;
smercurio_fc
2008-08-08 15:40:07 UTC
Permalink
Did you install AutoIt? To answer your question, yes, I was able to send the filename to the application using the AutoIt example I posted. You said&nbsp; The keys you see in the cluster array are random.&nbsp; ... OK, so then what's all that code you're doing in the first inner loop, and the prepending of some characters for? There seems to be a problem with the way keybd_event is being used or programmed. I'm guessing you probably got that example from <a href="http://forums.ni.com/ni/board/message?board.id=170&amp;view=by_date_ascending&amp;message.id=177906#M177906" target="_blank">here</a>.&nbsp; I'll try to take a look at it later.
TheStig
2008-08-08 16:40:07 UTC
Permalink
Yes, Autolt is installed. BBList opens but the curser just sits and blinks to the right of *.*.
&nbsp;
Sorry about the random comment. What I ment to say is the cluster array constant is random. If the file name string was working the next step is to keystoke "Enter" then "Alt C" etc. The constant will cantain these keystorkes.
&nbsp;
Before getting to this point I had to do a batch extraction using this vi. It worked flawlessly. The difference is I was controling a windows application (powerarchiver 2001).
&nbsp;
&nbsp;
craigc
2008-08-08 16:10:05 UTC
Permalink
Just a thought, i may be missing the point completely
Is it possible to get LabVIEW to write a text file of the commands you want to send.&nbsp; Then save this file as a batch file.&nbsp; Then run this file under system exec.&nbsp; This way you could do all the listings of files etc under LabVIEW and use system exec to run the command.&nbsp; for each different file LabVIEW will autogenerate a new Batch file and run it again.
CraigMessage Edited by craigc on 08-08-2008 10:44 AM
smercurio_fc
2008-08-08 16:40:08 UTC
Permalink
Strange. The example I put together using AutoIt works for me every time. The name of the file gets entered into the text box in the application. This shouldn't be necessary, but ... did you try rebooting the computer? (It's Windows.)I don't have time to look at the keybd_event method right now. It'll have to wait until this afternoon. Sorry. If someone else wanders by perhaps they may have a chance to look at it before then.
TheStig
2008-08-08 17:10:04 UTC
Permalink
There is no actual error code. What happens is BBLIST is executed (no typing occurs) and the vi runs continuously. The stop button does not work (kind of like an infinite loop) and&nbsp;I receive a Resetting VI message. I have to end task to stop the resetting.&nbsp;I tried a restart. I will reinstall and restart.
smercurio_fc
2008-08-08 17:10:06 UTC
Permalink
It sounds like the VI is waiting at the WinWaitActive node. That node waits until the specified window gets displayed. On my system the window name is "C:\BBLIST.EXE". Is it different on yours? You can try setting the nTimoutInput to, say, 5 so it times out after 5 seconds and continues on. An alternative is to set the WinTitleMatchMode property to 2 (Match any substring in the title) prior to calling WinWaitActive, and wire in "BBLIST" for the strTitle input of WinWaitActive.I'm still curious about the keybd_event function, though.
smercurio_fc
2008-08-08 18:10:07 UTC
Permalink
I took a look in more detail. The one problem with the VI is that you need to convert the filename to uppercase. Otherwise you'll get the wrong character codes. The conversion to U16 is unnecessary, but other than coercion dots it doesn't cause a problem. The other problem is that the scan codes should not be 0 for each character that you enter. The keybd_event function is really old and annoying. Attached is a modified version that should work. At least it did on my system.


Step3_bin_to_txt_mod.vi:
http://forums.ni.com/attachments/ni/170/347944/1/Step3_bin_to_txt_mod.vi
TheStig
2008-08-11 14:10:06 UTC
Permalink
Thanks, it works great.
&nbsp;
After messing with the code for a few minutes I came to the realization that BBLIST does not recognize strings in excess of 12 letters/numbers including the extension. Just something else to work around.
smercurio_fc
2008-08-11 14:40:14 UTC
Permalink
That's a DOS limitation (8.3 naming limitation). Given that the app is basically a DOS application, it's not too surprising.
Continue reading on narkive:
Loading...