Send a keyboard event from labview to C#

Hi,
We currently have a program in c# that takes keyboard inputs from a user and will fly a quadrotor. We aim to have a LabView .vi generate keyboard commands based on our experiment and send the commands to the c# code creating a feedback loop where the .vi will keep track of sensor and experimental data.
Our problem is that we have tried many different methods to send the keyboard commands in LabView. 
1) http://zone.ni.com/devzone/cda/epd/p/id/3711
2) http://forums.ni.com/t5/LabVIEW/Send-keyboard-commands-to-another-windows-program/td-p/330670/page/2
as well as other variations and similar .vi's that do the same thing. Here is an example of a .vi used to press the letter "t" once.
http://i.imgur.com/hwmjZ.png
All of them can write the string to a text (open notepad put cursor in blank window) file but none can do it in such a way that it is detected by the c# code. On my own I can open and run the c# code and press keyboard buttons myself and the commands are recognized, so I think it could be an issue with how LabView sends the keyboard events and how c# reads them. Here is the c# code segment that we are using to read the input commands:
public override List<String> GetPressedButtons()
          KeyboardState state = device.GetCurrentKeyboardState();
          List<String> buttonsPressed = new List<String>();
          foreach (Key key in Enum.GetValues(typeof(Key)))
                    if (state[key])
                              if (!buttonsPressed.Contains(key.ToString()))
                                        buttonsPressed.Add(key.ToString());
          return buttonsPressed;
Can anyone help trying to figure out why using the keybd_event function in LabView can not interface correctly with the above detection code in c#? I can provide any code and clarification if you think it can be helpful.
Thanks,
Andy

Hi,
I can't say with certainty where the problem is or even how many there are. I do know that the KeyboardListener.cs class should work according to what I have read online. I also know that if I press the keyboard myself then the state is changed and the correct action is taken. If I try to issue an event from Labview then the event is not captured. Here is the code, it is rather large ~20 MB.
https://www.dropbox.com/s/vsvcje1ro364otu/ARDrone.zip
https://www.dropbox.com/s/p3h3tj8bcqc29gk/Forward_backward0924.vi
The key listener is in ARDroneInput>Utils>KeyboardListener.cs and the polling takes place in ARDroneInput>KeyboardInput.cs
The reason I wanted to use keyboard inputs is because the quadrotor we are using takes keyboard commands W,A,S,D,T and L. Initially I thought having Labview issue these commands would be the simplest method. That may not be the case.
I was just thinking that it is not necessary that key events are sent from Labview. Instead, one could send an array representing the frequency of each button press rather than the button press directly. In that case an array that is updated continuously from Labview will just have to be kept track of in the C# code. The C# can then convert that to whatever control input we want. Can it be easier to send a vector of numbers in real time to C#?
If you think it is better to establish a connection between Labview and C# using .NET to send keyboard commands (rather than the vector idea above) can you explain that a little more? How does one go about doing that? If you think the vector idea is simpler how should the interface be set-up?
I just talked with my collegue and we think that maintaing a .txt file in Labview and having C# read it is the best option. We will begin working on that and will update you tomorrow.
Thanks,
Andy 

Similar Messages

  • How do I send the iPhoto events from my iMac to my iPad when the two devices are connected by USB port?

    I connected my iPad to my iMac via USB port.  I want to send my iPhoto events/files to my iPad.  I cannot find the right instructions.  It appears to me that the iPad sync only transmits data from the iPad to the iMac, but I am trying to send iPhotos from the iMac to the iPad.  Do I use export or sync?

    You need to use iTunes to sync photos.
    Connect your iPad to your computer. Launch iTunes. Select Photos from the menu. Click the Sync button bottom right side of the iTunes window.
    Syncing iPad, iPhone, or iPod touch with iTunes
    iPad User Guide

  • What files do I send to be upgraded from LabVIEW 5.1.1 to LabVIEW 2012?

    OK.  Just to be clear.  I am a complete newb to ANYTHING LabVIEW or LabWindows related.  I am a programmer, but I have never used any version ever.  That said, I am responsible for the upgrade process of getting our old LabVIEW 5.1.1 system up to date.  The old system (still running and doing it's job everyday), is an old Windows NT v4.0 SP6 system running LabVIEW 5.1.1.  You can just imagine how ancient this is by today's standard.
    Have I set the stage properly?  I hope so.  Newb, Ancient LabVIEW version 5.1.1, Windows NT 4.0, upgrading from 5.1.1 to 2012.
    Now here is what I "think" I know about what is required.  Because LabVIEW 2012 will not directly read in, process and /or compile LabVIEW 5.1.1 files, I must first open and save the files using an intermediate version of LabVIEW (specifically 8.2.1) to bring the files up to a version that 2012 can handle.  I have noticed in reading the Version Conversion forum, that I can attach a zip file of my LabVIEW files and one of the resident Gurus will convert it for me and give them back - quite nice I think.
    Now, I have what I think are all of the required LabVIEW vi and llb files that make up this system we have in place, but I want to be sure before I just post a bunch of stuff.  
    What exactly do I need to zip up and what can I leave out? 
    Are there LabVIEW vi and llb files in a "project" that are not needed? 
    Are there any setup/configuration/project specific files I need to include? 
    Are there any limitatations to this conversion process that I need to be concerned with - such as various toolkits/suites/modules that may have been used but are no longer supported?
    Secondly, I am not really comfortable with posting my vi and llb files for the world to see (and possibly use) as I am not the owner of said modules, just the user/future developer who will be responsible for insuring they stay up to date.  Is there any way I can send my files to a specific NI guru via email instead of just posting them?
    Solved!
    Go to Solution.

    So if I understand you correctly,  all I really need to do is to get LabVIEW 8.2.1, and update my .vi, .lib, and any .ctl files to that version.
    Is it a simple matter of just opening the files and hitting something like SAVE AS, or just SAVE and it will do this?  Once done, LabVIEW 2012 will then allow me to open them and do what I need to do?  Do I have to save them into LabVIEW 2012 first, or is that automatic when I try to recompile them?
    When I get a copy of LabVIEW 8.2.1 (eval version), do I have to get all of the pieces (modules, toolkits, etc.) in order to update the 5.1.1 files?  Based on what is installed on that NT v4.0 system, we have the following items installed:
    NI VISA
    NI ComponentWorks 3D Graph
    NI DataSocket
    NI LabVIEW 5.1.1 Advanced Analysis Library
    NI LabVIEW RTE 5.1.1
    NI LabVIEW v5.1.1
    NI Measurement and Auto Explorer 1.1
    NI-488 2.1.60
    NI-DAQ 6.6
    NI-PAL 1.3.110
    NI-Reports
    NI-VXI/VISA
    You mention DAQ.  Our program uses NI DAQ v6.6 now.  I have LabVIEW Developer 2012, so I just download the DAQ files for it and it will replace the NI DAQ v6.6 library files we use now? 
    Thanks for your help so far.  If we had a support contract in place, this wouldn't be an issue.  However, as I stated, I am not the owner of the files, just the currently assigned caretaker, and part of my task is to get from where we are now on this ancient hardware/software platform, to the latest and greatest.  However, I am specifically not allowed to just place the files on a public forum for all to see.  It just isn't done.  We can send them to a known location and a known entity, but not to just anyone/anywhere as a public forum is by its very nature.   
    I know there is nothing you guys can do if I cannot give you the files, but thanks for helping me to do it myself.    Getting an eval copy of 8.2.1, et. al is probably what I have to do here.

  • User events from labview build dll

    Reference to pattern
    Previous discussion
    I had this pattern in place in a LV 7.1 application using a LabVIEW
    build DLL, but when migrating to LV 8.5 I found that User Events
    created in one application instance can not be fired by another
    application instance. It seems that since LV 8.x a LabVIEW build DLL
    are a different application instance. The generate user event function generates an error inside the DLL stating that it is not working because it is a reference from another application instance.
    Is the behaviour of a LV build DLL different than a C build DLL? Is the C build DLL part of the same application instance as the LV executable?
    Is there a way the get the LV build DLL to be a part of the same application instance as the LV build executable or development environment?
    Regards,
    André
    Using whatever version of LV the customer requires. (LV5.1-LV2012) (www.carya.nl)

    Forgot to tell that I rebuild the DLL in LV 8.5, before making that conclusion.
    Message Edited by andre.buurman@carya on 09-04-2008 01:12 PM
    Regards,
    André
    Using whatever version of LV the customer requires. (LV5.1-LV2012) (www.carya.nl)

  • Sending an apple event from C (not iPhone)

    I'm trying to send an "open documents" event. It's giving me a -50 error (incorrect parameter) so I think it's in the aeDirDesc that gets added as the parameter, but I can't seem to find enough documentation to see what's wrong. Here's my code which is altered from a (working) chunk of code which tells finder to open an app.
    Sorry about the large code fragment...
    <pre>
    OSErr errT;
    OSType desc;
    AEDesc progAddr, aeDirDesc;
    char preview[PATHLEN];
    uchar previewU[PATHLEN];
    uchar doc[PATHLEN];
    AppleEvent someAE;
    FSSpec fspT, fspP;
    AliasHandle DirAlias = NULL;
    AEDesc fileList;
    strcpy(preview,"file://Applications/Safari.app");
    pstrcpy(previewU, "\pMacintosh HD:Applications:Safari.app");
    pstrcpy(doc, "\pMacintosh HD:tmp:dockeepimages:Page-001");
    errT = FSMakeFSSpec(0,0,doc, &fspT);
    errT = FSMakeFSSpec(0,0,previewU, &fspP);
    SendOpenToFinder(&fspP);
    errT = NewAlias(nil, &fspT, &DirAlias);
    HLock((Handle)DirAlias);
    errT = AECreateDesc(typeAlias, (Ptr)*DirAlias,
    GetHandleSize((Handle)DirAlias), &aeDirDesc);
    HUnlock((Handle)DirAlias);
    errT = AECreateDesc(typeApplicationURL, preview, strlen(preview) +1,
    &progAddr);
    if(errT == noErr)
    errT = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments, &progAddr,
    kAutoGenerateReturnID, kAnyTransactionID,
    &someAE);
    AEDisposeDesc(&progAddr);
    if(errT == noErr)
    errT = AEPutParamDesc(&someAE, keyDirectObject, &aeDirDesc);
    AEDisposeDesc(&aeDirDesc);
    if(errT == noErr)
    if ((errT = AECreateList(nil, 0, false, &fileList)) == noErr) {
    errT = AEPutDesc(&fileList, 0, &aeDirDesc);
    AEDisposeDesc(&fileList);
    if(errT == noErr)
    errT= AESend(&someAE, 0, kAENoReplykAEAlwaysInteractkAECanSwitchLayer,
    kAENormalPriority, kAEDefaultTimeout, 0, 0);
    </pre>
    There's no error until the AESend which gives a -50...

    etresoft wrote:
    I wouldn't mind use AppleEvents (not the same as Applescript!) via the Script bridge or something. However, I thoroughly detest Applescript.
    The AppleScript language has one major defect: in order to provide high-level readability, it sacrifices low-level semantics. i.e. Even a complete non-programmer can look at an existing AppleScript script and get a general idea of what it does, but actually figuring out the precise mechanics of how it works requires a load of effort by newbies and expert programmers alike. "English-like" syntax is all well and good, but without all those ugly brackets and braces, it can be a real PITA figuring out what's a variable name, what's a property name, what's a command, and so on. You can't tell from syntax alone as all the different structures look exactly the same - it's hopelessly ambiguous. Allowing whitespace in application-defined keywords also makes it tricky to tell where each keyword begins and ends. e.g. Is 'foo bar' a property name, or a constant name, or a command name, or a command name followed by a property name, something else? (One tip for you: in Script Editor's preferences, set the 'application keyword' style to use underlines.)
    (AppleScript also has a whole bunch of lesser defects, of course... but hey, find me a language that doesn't. Come to think of it, even Apple events themselves are a bit wonky; and don't get me started on the mess that is the Apple Event Object Model or the Cocoa Scripting framework.)
    OTOH, I will say two things in the AppleScript language's defense:
    1. AppleScript frequently gets blamed for the bugs, inconsistencies, appallingly inadequate documentation and other defects of individual applications' scripting interfaces. This is not AppleScript's fault, however; it's the developers who wrote those applications who are to blame - and their failings affect all Apple event-capable languages, not just AppleScript.
    2. It still has the best Apple event support of any language. Scripting Bridge, which you mention, doesn't work properly (various bugs, lacks various bits of functionality, and is prone to application incompatibilities), and [ironically] obfuscates and confuses the process of building and sending Apple events much worse than AppleScript does. Even appscript, which [AFAIK] provides the next best Apple event bridge after AppleScript, still chokes on the occasional application command that works without problem in AppleScript. (Of course, some of those compatibility problems are due to applications relying on behaviours that in turn rely on AppleScript's own undocumented quirks; but hey, you work with the APIs you've got, not the ones you wish you had.)
    Control AppleScriptable applications from Python, Ruby and ObjC:
    http://appscript.sourceforge.net

  • Has anyone ever figured out how to interact with PP events from LabVIEW?

    We would like to know how to interface a motor control system with a powerpoint file such that after each motor step is complete the next slide is shown and so on.
    Direct contact can be made via [email protected]
    Cheers Jim & Jon

    You can use PP or just put your graphs in a picture control, easyly passing from one step to the next. If you prefer using PP, you could use ActiveX, as is done to control Excel within LabVIEW.
    Good luck

  • Capturing typed keyboard events from another app

    Hi everyone, thanks in advance for any help you might be able to give me.
    I have written and inventory app and an point of sale app. I need some way to capture what is keyboarded into the inventory app so that I can fire some events in the pos app.
    How can you capture typed keypresses if your app doesn't have direct focus? Can I request focus without impeding what is being typed into the other app??
    Any ideas would be greatly appreciated ...
    Ken.

    You won't be able to request the focus and continue letting the user type in the inventory app.
    My idea to solve your problen: accces to the event queue inventory aplication and make a copy of the events that suceed in it, letting the inventory aplication consume normally it's event and fowarding the copy to the other aplication.
    abraham.

  • I have to send the start impulse from labview to trigger generator?

    i have to send a start impulse to the trigger generator, logging the actual time and requesting the actual time code of Digital video recorder.

    Hello;
    Could you give us more details of your application?
    Filipe A.
    Applications Engineer
    National Instruments

  • User event from TestStand to Labview

    Hello all,
       I have some question regarding Labview-TestStand
       We have a large application written in Labview, user interface separated from the actual
    core using  User Events. Now we consider to automate some repeated actions with slightly
    different parameters. Is the TestStand sutable option for thi case? Can it send the "User event" to
    Labview?
     Thanks
    Michael.
    LV 8.2 at Windows & Linux

    Hi mishklyar,
    tbob makes a good point, and I will try to elaborate a little bit. TestStand is test executive software. It works by executing a set of predefined steps in sequence. These steps can be LabVIEW code, C code, etc. You can pass parameters into the LabVIEW code that you call, but you cannot directly send "user events" the same way that user events are created in LabVIEW by interacting with front panel controls. The traditional design with TestStand is to create a LabVIEW code module that does a particular thing, and have other modules (VIs) that do other things. Then, call each module from TestStand as needed. As the name implies, TestStand is often used for testing products, but could be used for other purposes as well. If your application could be modified to fit this model, then TestStand could probably be used. However, you would probably want to architect your LabVIEW application differently than it is right now.
    Best Regards,
    John M
    National Instruments
    Applications Engineer

  • Sending events from a child frame to a parent

    My application has a main Jframe which instantiates and launches sub-frames. I'd like to send a mouse event from a sub-frame back to the main frame (child to parent).
    For example imagine this simple program: jFrame1 has a text box and a button. When the button is pressed a new instance of a different frame (jFrame2) is launched. The user moves the mouse over to jFrame2 making it the active window, and then clicks somewhere in the frame. The text box back in jFrame1 gets set to the X coordinate of the mouse click over in the other frame.
    Thanks in advance for any responses.

    One way that could work would be to use the Observer pattern here:
    http://en.wikipedia.org/wiki/Observer_pattern
    Quick question though: why are you spawning child JFrames and not JDialogs? The dialogs would seem like a more natural fit.

  • How to send a message(apple event) from mac os to our application

    on developer.apple.com i found a method which opens a given documetns through an apple event.
    my question is how to send open document event from mac to our application on xcode

    Assuming you're using Cocoa, the simplest solution is to call -[NSWorkspace openFile:withApplication:]. Example:
    NSWorkspace *ws = [NSWorkspace sharedWorkspace];
    NSString *appPath = [ws absolutePathForAppBundleWithIdentifier: @"com.apple.textedit"];
    [ws openFile: @"/path/to/file" withApplication: appPath];

  • How to import a string array from labview into DIAdem Spreadsheet/table

    How to set up a diadem template so when using labview diadem express, the values are imported into a table.
    I have values such as gain, corner frequency, and pass/fail that exist in arrays generated from collecting information from a 7 electrode EEG system.  I want to create a table/spreadsheet in DIAdem that imports the data when using the LabVIEW DIAdem express function, into a table or spread sheet?
    Any takers?
    -Regards
    eximo
    UofL Bioengineering M.S.
    Neuronetrix
    "I had rather be right than be president" -Henry Clay
    Solved!
    Go to Solution.

    Hi eximo,
    The DIAdem Report express block makes it easy to populate text boxes and 2D graphs in DIAdem from variables (wires) in LabVIEW.  Unfortunately neither 2D tables nor 3D graphs are implemented in the DIAdem Rerpot express block.  So you've got 2 options.
    Option 1:  if you don't have too many strings that you want to display, you can arrange that many text boxes into the shape of a 2D table and use the DIAdem Report express block as it was intended (sending data to it from LabVIEW wires).
    Option 2:  at some point as you continue to add elements to your report, you'll probably end up here.  The DIAdem Report express block was designed to connect LabVIEW wires with simple DIAdem reports.  But there is a hook you can use in the DIAdem Report express block to run a VBScript instead of loading a REPORT template *.TDR file.  With a DIAdem VBScript you can accomplish anything in DIAdem.  In addition to wiring up a VBScript path instead of a REPORT template path, you'll also need to send all the data you want to report on to a TDMS file and have DIAdem read the data from that file, instead of receiving the data directly from the LabVIEW wire at the express block's input terminal.  This is a little more complicated, but it will allow you to do absolutely anything you want to in DIAdem and start that report from LabVIEW.
    I'm attaching an example of Option 2, but I'd be willing to help you adapt it to your data and reporting needs if you'll post or email ([email protected]) your data set and a rough *.TDR file of what you want in REPORT.  It's pretty slow here at the office over Christmas, so I've got time....
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments
    Attachments:
    DIAdem Report File.zip ‏90 KB

  • I cannot add enchange calender events from my iphone

    I am trying to send a calender event from my Iphone  to my Outlook 2010 calender.  we are running Exchange server 2010 at work.  The event just never shows up on outlook.

    Sounds like a problem with the email account. You can try and turn the account off, don't delete it. Then power the phone off/on and then turn the account back on. See if that helps. If not, then turn the account off and do a reset on the phone. Hold the sleep/wake and home buttons together until you see the Apple logo and then release. After the phone restarts, turn the account back on. If that doesn't do it, then delete the account from the phone and then recreate it. That should fix it.

  • [solved] send keyboard event / key to specific background window?

    Hi!
    So... is this possible / how? I'd like to send keyboard events to a window in the background - maybe even in regular intervals. While I'm dong something else, in another window (or nothing).
    Thx!
    Last edited by whoops (2011-07-21 11:05:44)

    Actually I'm thinking, maybe there is a totally another (better?) way to do what you want. I usually find that automatizing tasks in linux differs very much from the windows experinece, most of the times scripting is the most powerful and easy way of doing things. So if you describe to us what you want to accomplish, maybe some experienced linux gurus would give you some advices that sets you off course from sending keys and mouse events. I used to do that in windows with autohotkey, but now in linux there was no need for that so far ever, except for using system wide abbreviations with autokey.

  • LabView user-event from external dll source

    Hi!
    I'm dealing with the following issue:
    I use a CAN sniffer device, wich sends data over USB to a PC. The main goal is to create a vi that can process the incoming data. I already have a vi wich works with polling mechanism. It calls external DLL functions with the "Call library function node". The main problem is the polling mechanism.
    I would like to recreate this vi so that it would work event-driven. I have an other application, written in C++, that does the same thing, and it gets interrupts from a DLL, when a new data is available in the input buffer.
    The callback mechanism is implemented in the DLL.
    In LabView I would like to do tha same thing. There is the "event case structure", but there is no option for defining such user-events, that i would prefer.
    I have found a similar topic, there the solution is "occurrences". The occurrence is called from a DLL, too. But this solution uses the "waiting for occurrence to set", that is an endless-loop-like thing.
    The other thing I've found is the ActiveX and .NET events. I don't know, probably that is the solution.
    Anyway: is there a possibility to create such events, that can be generated from a simple external DLL and can be handled by "event case structure"? How should I do this?
    Or how NI does this? I mean that NIs DAQ cards must use some similar methods for data processing. Is there some tutorial or support about it?
    Thank you for your answer!

    2716jag wrote:
    Hi Wiebe,         From your answer i have a doubt that What it exactly means "If the dll is used from within LabVIEW". Also i want to know Is there any way to access the functuions defined in the .SYS file in Labview Environment. Regards,Jagan Can you be a litte more specific with your first sentence. I have no good idea what you mean. A .sys driver is usually a kernel device driver. This driver has to be started and run in the kernel subsystem which LabVIEW can not access directly. Such a driver is initialized using the CreateFile() Windows API. The returned handle is then used with other API functions such as ReadFile(), WriteWile(), DeviceIoControl(), and finally CloseHandle().Theoretically you could call all this APIs directly from within LabVIEW using the Call Library Node. In practice you do not want to do this even for fairly simple kernel drivers since the parameters for those APIs do get fairly complex in most cases, and you usually do also want to have some sort of asynchronous operation using events or such to make the driver access user friendly. All these things are most easily handled in a user space DLL written in C that exports a more LabVIEW friendly API that you can then import into LabVIEW using the Call Library Node. Usually most kernel device drivers do come with a accompagning user space DLL already, as this is the only sensible way of accessing such a driver. So you can usually look for the documentation of that user space DLL API and go from there trying to import that into LabVIEW using the Call Library Node. Even then it may not be easy at all if that API uses complicated function parameters and even completely impossible if it uses callbacks or such, requiring you to write a so called wrapper DLL that translates between the native API and a more LabVIEW friendly API.  You don't have to believe me but I can guarantee you that if writing such a user space DLL or wrapper DLL is beyond your capabilities, trying to go directly about accessing the Windows APIs in LabVIEW to access a kernel device driver is going to make you squirm in real pain. And those knowing how to write such a DLL would never even consider spending the time to try to access a kernel device driver directly from LabVIEW. Rolf Kalbermatter

Maybe you are looking for

  • Calling a Web Dynpro application from a web application

    Hi everyone, I've got a problem I hope someone can help me resolve. What I wanna do is to show a login form, which is part of a J2EE web application (contained in a SAP Web AS), an after the user submits the required information, I have to redirect t

  • ITunes Authentication with Windows Vista

    I've recently upgraded to Windows Vista. It would seem the computer authorization then becomes broken - my complete purchased library became unplayable without having to authorize another computer for each song (even though it's the same machine), an

  • Create a script to create multiple objects without using execute immediate.

    I have a function that requires several objects (4 types, 8 functions) to run. Right now they're in separate sql files. I'd like to combine them into one file that I would run but I'd rather not use the 'execute immediate' since it seems like you hav

  • Possible to run 10.5 version of Preview in 10.6?

    Does anybody know if you can install (I know how to do it with pacifist) and run the version of Preview from 10.5 in snow leopard? I like the old version of Preview much better.

  • Problems installing htmldb 2.0, totally new db/http server/htmldb install

    I grabbed the new version of htmldb 2.0 and followed the install instructions that came with the htmldb 2.0 seperate download file. The scripts run fine etc. Evrything at default with default example db - orcl. But at a certain point I need to config