LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help wanted using user32.ddl

I am trying to generate a keypress using the user32.dll, see attached VI.
For testing I am trying to toggle the numlock light on the keybaord.
I can get the light on, but not off.
 
Please take a look at this VI and see what I am doing wrong.
Kind regards,
Ferry
 
0 Kudos
Message 1 of 8
(3,942 Views)
Are you doing this for fun, or to practice to use DLL ?
I looked in your VI and noticed that there is no wait between your two sequences, so as soon as the first one is finished, it jumps to the second one. I don't know if this is the behavior you are looking for.
 
If you just ned the keystroke functionnality, you can use the Event structure and, "edit events handled by this case" then chose "This Vi" event source and chose "Keydown" event.
Then you can check which key was down and so on.
 
Hope this helps.
 
Cheers.
Doc-Doc
It would be nice if you take the time to rate this answer
http://www.machinevision.ch
0 Kudos
Message 2 of 8
(3,939 Views)

Thanks for your reply,

I like to find out how to generate keystrokes using this library.

I`ve added a 100ms time delay.

 

Ferry

 

0 Kudos
Message 3 of 8
(3,936 Views)
  1. You should not use a DBL in the function prototype if the type is DWORD. At least in my computer it doesn't seem to like it.
  2. The function does not toggle the light, but the key. This means that you need to push and release the button twice. To push the button you should wire 0 into all the parameters and to release you should wire 2 into the dwFlags parameter. You can also search for a VI called Simulate Keyboard which will already have an enum with the list of all the keys.

___________________
Try to take over the world!
0 Kudos
Message 4 of 8
(3,933 Views)


@tst wrote:
  1. You should not use a DBL in the function prototype if the type is DWORD. At least in my computer it doesn't seem to like it.
  2. The function does not toggle the light, but the key. This means that you need to push and release the button twice. To push the button you should wire 0 into all the parameters and to release you should wire 2 into the dwFlags parameter. You can also search for a VI called Simulate Keyboard which will already have an enum with the list of all the keys.



Thanks, got it working. Where did you find to wire a 2 into the dwFlags parameter?

0 Kudos
Message 5 of 8
(3,928 Views)

I looked inside the VI I mentioned, which I have on my computer. It comes from a collection of tools called LV Toolbox.

One of the problems with calling windows API functions is that they use string constants which have numeric values and in LV you can only use the numeric value. To find it, you have to look for the constant definition in the header file, but if you don't have the header file in your system you will have to search for it online, which can be a bit of a hassle. 


___________________
Try to take over the world!
0 Kudos
Message 6 of 8
(3,920 Views)

Two problems I find when using the user32.dll or any other win32 type dll are matching complex data structures (like handles to object with pointers in them) and passing constants which are defined by bit-fields which are often defined in a header file with pre-processor directives.  These constant aliases are not easily accessible and need to be looked up in the header file.  Is there an automated method of dealing with these problems.  Other than these issues, working with the user32.dll is not all so bad, just wish there was prototype information built into the dll and configures the dll node appropriately without the time consuming process of looking through the documentation.  Tst's suggestion of using the event structures are a good one since they are simple and quick to use especially for capturing keystrokes.  The event structure also should be more machine and OS independent than using the windows API directly.

 

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 7 of 8
(3,915 Views)

Paul, the suggestion wasn't mine, and it only helps when capturing keystrokes, not when you want to simulate them.

I agree that it would be nice to have the CLFN automatically configure, but I don't think the DLL holds that data and without it I don't see how it can be done.


___________________
Try to take over the world!
0 Kudos
Message 8 of 8
(3,909 Views)