Keystroke Device Tracing (Delphi) [duplicate] - delphi

I have two keyboards attached to a PC. One is used to type in TMemo1 and the other in TMemo2. Both are allowed to type at the same time. The problem is I cannot distinguish what keyboard-one has typed and what keyboard-two has typed.
Is there any way to distinguish, which device certain input came from?

#Dian, you can use the RegisterRawInputDevices function to register the keyboards and monitor the WM_INPUT message to determine the device (keyboard) where the input came from.
check theses links for more info
Using Raw Input from C# to handle multiple keyboards
WM_INPUT Message

As far as I know there is no way to distinguish keyboards unil you have hooked keyboard driver. Windows provide solid input model to application, so there is no difference for application receiving input from keyboard, second keyboard, IR remote control, or from another program that uses SendInput API function.

Related

How to debug Human Interface Device?

I have a bar-code scanner with USB interface, so it appears as an HID.
There are reasons why I must breakpoint on the first character.
That brings my Delphi IDE to the front, it stops on the breakpoint and the rest of the bar-code is injected into my code as if it had been typed front the keyboard (which, in a way it has, as the USB scanner is just another HID).
Is there any way to avoid this? Or to add an initial check as to the source of the input?
It annoys me so much that I am now looking for a scanner with an RS232 interface.
The problem is that HID "devices" send information back to the computer in packets known as "reports".
In the case of a mag-swipe, or bar-code scanner, the "report" contains the entire number.
Which is to say, you don't receive reports character-by-character, but the entire string at once. (In the case of a mag-swipe, you will receive all two, or three, tracks in the same report).
So your code doesn't break "on the first character", it breaks "on the entire report". The fact that the remaining characters are there you can think of as a bonus (if you don't want to look at them you don't have to). But you won't be receiving any more "reports" for subsequent characters.
i cannot imagine any reason why you wouldn't want to know the bar-code at once. But most mag-swipe and bar-code scanners can be configured to emulate a keyboard, rather than a generic HID device. In that case you will receive multiple WM_KEYDOWN messages.

How to read value from simple USB device?

I have an exceedingly simple USB device. There is no driver provided and instructions are to open an editor and manpulate the device (let's not confuse the issure by dicussing the device) to see the result.
Sure enough, if I open Notepad in Windows and manipulate the device a text string appears in Notepad.
Ok, it looks like it is writing to stdin. Now I would like to write a Delphi program to take this input and act upon it ...
How should I best go about it?
The form doesn't seem to be receiving KeyDown/KeyUp/KeyPress events. That's a pity as it would allow the device to 'interrupt' me. But, maybe I have to poll? Every so often (how often?) I could attempt read from stdin - but what if there is nothing to read?
I hope that I explained that clearly. Any advice?
Update: oops, my bad - I wasn't receiving KeyDown/KeyUp/KeyPress events because I forgot to set the form's KeyPreview to True. But I am awarding the question to Greg because he tried to help and because HID looks interesting. Thanks, Greg.
It sounds like your device is using the HID (Human Interface Device) USB class and is acting like a keyboard. So, you would read from the keyboard exactly as you normally would, manipulate the device in whatever way is appropriate (scan a bar code, whatever) and the keystrokes will come through as if they were typed.

Delphi - alternative solution for a global keyboard hook

sorry for this little bit strange title, didn't found a better one..
I've got the following situation:
I have a PC with an RFID reader connected via USB.
I now need a program which pops up when ab transponder was scanned the the RFID reader and shows the scanned value. (The reader just simulates keystrokes)
Problem: the value of the transponder is something like 0001230431, and I can't change it. (To prefix a hotkey combination or so)
So I have thought about using a global keyboard hook, check if three zeros where typed in, capture rest of data and when the 10 digits are complete, call the application through an automation object and show the number.
But I'm not very exalted about using a global keyboard hook. Many AV programs don't like them very much, they are not so easy to handle with Delphi and I guess that's not very resource-friendly for such a little task...
So I'm looking for an alternative solution...maybe somebody has an idea?
Big thx!
ben, you can use the RegisterRawInputDevices and GetRawInputData functions.
first you must use the RegisterRawInputDevices function to register the input device to monitor and then you can retrieves the data from the input device using the GetRawInputData function.
Check theses functions too
GetRawInputDeviceList retrieves the list of input devices attached to the system.
GetRawInputDeviceInfo retrieves information on a device.
Why not make sure the Delphi app with a text edit control has focus before the scan is done? Then the keystrokes will go straight into your Delphi app.

How to create a BlackBerry App that access low level hardware?

I've written some BlackBerry apps, but now i'm trying to write one that must access the hardware (keyboard) in some low level way, and I can't seem to find a way to do it, nor any help to it in the 'official' boards.
The thing is, I need to know when, at any time, the '$' key is pressed in the blackberry keyboard, so my app (or resident service) can catch it, stop the '$' char from displaying, and if the user presses a vowel next, then add an accent to that vowel... and if it presses another key, just send back the '$' char + the other char.
i.e. '$' + 'a' = รก
In other words, I need to create an app or service that converts the '$' key into an accent key, just like typical non-US PC keyboards works.
Now here's the problem: The whole Blackberry OS works under a Java Virtual Machine (Kind of making the JVM the actual OS). So as you can imagine, every app written for it is written in Java.
There's obviously a set of special blackberry api libraries into their Java implementation so the developer is able to access particular Blackberry functions and features... however there doesn't seem to be a thing that I can use to achieve my particular task.
But then maybe there is, and I haven't found it, since I'm still new to Blackberry Programming.
So, in that note, any help or comment will be greatly appreciated.
-Gabriel Alonso.
A screen need to have the focus to be able to get key Event.
RIM dosen't allow low level access to their hardware for security reason.
Press and hold a letter key and roll the thumb-wheel to scroll through international/accent characters, equation symbols and other marks.
Here is the source
Blackberry do not allow execute applications, if they use certain API, not to mention the low-level programming.
All that you can use in your applications for keypad handling - it is possibilities of Java. Like KeyListener interface and Keypad class.
This is a very late reply, however...
You can use keyChar (member of screen, and of KeyListenerInterface) to intercept any key - for the first letter, capture the key pressed. If it's "$" hold onto it and don't call super.keyChar. On the next keyChar (or after a delay with no input) perform your mapping if $ was previously pressed, and send your designed character code to the super.keyChar call. keyDown and keyUp can be used similarly if keyChar presents implementation issues.

Bypass keyboard,mouse input and let SendInput pass

I'm making user definable key macros to a program. (Those macros are limited to that program.)
I'm using TApplicationEvents to record key messages. And then use SendInput to play them back. But I need to disable mouse and keyboard so it wouldn't interrupt playback.
I can't use JournalPlaybackProc and JournalRecordProc because they are subject to UAC, UIPI in Vista and Win7.
Is there a easy way to block mouse and keyboard input while still using SendInput. (A way that doesn't need heightened privileges.)
Also I need one escape key that stops playback.
EDIT:
TControl.Perform didn't work because it ignores hotkeys.
I thought of using reserved nibble (bits 25-28) in WM_KEY messages, but in the windows documentation it says it's reserved and do not use. What could be the consequences.
If you want the 'artificial input' to be limited to your own application, I wouldn't use SendInput. If you use TApplicationEvents.OnMessage to record messages, I would add a 'if not(PlayingBack) then' check in the OnMessage when playing back a macro and use Form1.Perform
I have always used AutoIT's DLL for sending KeyStrokes as well as Blocking Keyboard and Mouse.
There is one thing and that is AutoIT can't block Ctrl+Alt+Del keys.
Do check it out.
HTH

Resources