VB6 - reading from keyboard in an ActiveX DLL - dll

I have an ActiveX DLL which currently reads from a serial port. Now I want it to accept input from a USB device.
The USB device functions as a standard Human Interface Device. That is to say, if I open Notepad then the device's output will appear in Notepad as if it were typed on a keyboard.
Normally, I would capture Key Up/Down events, but I think that I need a form for that and my DLL does not have a form.
How can I capture that input?
[Update] I found this http://us.generation-nt.com/answer/anyone-know-how-read-keyboard-input-within-an-activex-dll-help-7934442.html# which claims to do it, but the code there won't work as is uses the AddressOf operator, which can only be used in a .BAS file, so not in an DLL .CLS
I am not even sure if I am looking for a system wide hook or application specific.
Hmmm, http://www.xtremevbtalk.com/showthread.php?t=77216 says "You can't implement a global WH_KEYBOARD hook in VB - it requires a standard (non ActiveX dll) as it has to be loaded into the address space of all the running applications."
[Upper date] So, maybe I can a form, make it 1x1 pixel and invisible and have a function GetTheData which shows the form modally and collects and returns the data - either getting keyboard input at form level or into a (n invisible) control then closes the form returning the input.
Would that work? If anyone posts a working example I will award a bounty (I would prefer that the form not be visible on the task bar and have no close button; the user should not be aware of it, or able to close it, it should close itself when it receives enough input from the USB attached HDI).

You can use RegisterRawInputDevices to monitor HID devices' input but this requires a window to listen for WM_INPUT message which means subclassing the window.
Here is a working sample project: UsbBarcodeSanner.zip

I think you have better option,
using uesr32.dll you can do this task easily,
refer this link
you will be able to use this function
Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
This dll handles anything you want for user in windows.. refer Old Post
I hope this will help..

Related

Vb.Net: How can I trigger an event when a single instance program is opened again?

I've got a single instance (set up via .net) program that operates mostly from the system tray but also has a window.
Users often lose the program among their other system tray icons and believe the program isn't running, trying to open it again from the executable.
How can I detect, within my running program, that the executable is opened again? (So that I can maximize the window)
Thanks in advance.
Opening another copy of a single instance program will bring your form to the front by default, but when the form isn't visible, this won't have any effect.
This is what I was looking for
The MyApplication_StartupNextInstance event occurs when another instance is started. This can be used to call any additional functions you need.
In Project Properties, You can navigate to Application -> View Application Events and handle Me.StartupNextInstance from within Partial Friend Class MyApplication.
Direct all thanks to the comments.

MFC Custom Keyboard DLL Accessed from Application Dialog Box

The overall goal is to be able to access a pop-up keyboard through an application that I am making in MFC.
I have created a dialog box with an empty text field. I would like to be able to click the empty field and have an onscreen keyboard to enter in the data field.
Is there list of functions or tutorials that anyone can provide me with to be able to perform this function? Ultimate I will be making the keyboard from scratch, so any guidance would be useful.
My first thoughts (I might be wrong someone might correct me if i am wrong.)
1)Create your Keyboard Ui in an MFC DLL and export the KeyBoard Functions like LaunchKB(Int screenx,int screeny) and CloseKB()
functions.
2)I would subClass CEdit and CRichedit such that when the edit control gains or loses focus it would call LaunchKB() function with windows ScreenX coordinates where the keyboard has to be displayed or CloseKB().
3) A callback function registered to dll ,which would get called for every click on the keyboard with characters clicked and these characters are to be displayed in the edit control.
This is just my thought ,there may be better ways to implement as well.

VBNET Create HotKey shared only for the entire Application

Basically i am creating a vbnet system software. I want to create a shortcut key to lock the system with out affecting the windows explorer (just my system only). Is it possible to create one for that? Or let's say create a procedure that triggers anywhere whether the focus is on a control, on a form (whether shown as normal or modal), or on any other that has the focus on it.
I just need an idea. Thank you.
I think you could use hotkey registration to do it.
Here is one of a few existing walk throughs on accessing user32.dll to register a global hotkey
I think the key for you will be where to register the hotkey and make sure to unregister it when your application closes.

How to capture input from USB?

Searching found many answers along the lines of it depends on the device driver", but I don't think that it's that way here.
I have a cheap & nasty RFID tag reader. You just have to open notepad, touch a tag to the read and its serial number appears in notepad (I have not tried it in Linux).
Anyhoo, how can I programatically capture this serial number in VB.net (20088 express)?
Seem it work in keyboard emulation.
You can try to create a simple form with a textbox and check if the serial number appears on it when the tag is read and then manage the textbox events to retrive the info and set the focus correctly.
This probably works using keyboard emulation. The reader is pretending (to the PC) to be a USB keyboard, and simply sending the keystrokes.
If so you could do various things to check the keyboard input in VB.net. For a quick-and-dirty test, I would simply create a blank form with a textbox, make sure the textbox has focus, and read a tag. If the text passes to the textbox then the RFID reader is just passing keystrokes in, and you can use the textbox events to read the data (remembering to set focus to the textbox when you expect input).
If your app needs to do something more sophisticated with the input keystrokes, or you don't want them appearing in the control, you can trap and handle the keystrokes as they happen - the standard KB article on how to do this is here: http://support.microsoft.com/kb/320583

Launch an application and send it to second monitor

In VB 2008, I am using the class 'process' to launch and external application with a few parameters. Does anybody knows how can I send it programmatically to second monitor?
Also, is there any way to know how many monitors are activated?
Thanks.
You can locate your form on a different screen.
form.Location = Screen.AllScreens(1).Bounds.Location + new Point(100, 100)
When you launch an application, use the Process Handle to get the Window (hWnd). It's this hWnd value that windows API uses.
You will need to use the SetWindowRect method imported from User32.dll (see last link)
See also
Screen Class
VB .NET Dual Monitor
Get Window Handles Associated With Process in vb.net
Egghead Cage - hwnd position
MSDN - SetWindowRect API Call