I'm looking for a language or library to allow me to simulate key strokes at the maximum level possible, without physically pressing the key.
(My specific measure of the level of the keystroke is whether or not it will produce the same output as a physical Key Press when my computer is already running key listeners (such as MouseKeys and StickyKeys)).
I've tried many methods of keystroke emulation;
The java AWT library, Java win32api, python win32com sendKeys, python ctypes Key press, and many more libraries for python and Java, but none of them simulate the key stroke at a close enough level to actual hardware.
(When Windows MouseKeys is active, sending a key stroke of a colon, semi colon or numpad ADD key just produces those characters, where as a physical press performs the MouseKeys click)
I believe such methods must involve sending the strokes straight to an application, rather than passing them just to the OS.
I'm coming to the idea that no library for these high (above OS code) level languages will produce anything adequate. I fear I might have to stoop to some kind of BIOS programming.
Does anybody have any useful information on the matter whatsoever?
How would I go about emulating key presses in lower level languages?
Should I be looking for a my-hardware-specific solution (some kind of Fujitsu hardware API)?
I almost feel it would be easier to program a robot to simply sit by the hardware and press the keys.
Thanks!
Second solution, super convoluted, a ton of virtualization, diabolical, totally untested, but theoretically should work, unless the datasnip program doesn't actually write to the keyboard buffer, but instead simulates keystrokes like you've been trying to. That would suck, and I would find the description of their product to be highly misleading.
You'll need:
http://www.priority1design.com.au/datasnip.html
http://sourceforge.net/projects/com0com/
And some knowledge of writing to com ports... which, looks like there's a good python module here: http://pyserial.sourceforge.net/
First, write a small program that will send characters, hexcode, etc. as necessary to the COM port of your choosing. Second, create a virtual COM port pair using com0com. At this point, connect your program to one of the COM ports created, and datasnip to the other, making sure that both sides of the communication are using identical baud rates, parity and stop bits, and data length parameters.
At this point you should have a keyboard that is identical to a hardware one, as far as the OS can tell.
I used this solution http://oblita.com/interception.html
It fully meets my needs (sending keystrokes to direct input game)
Can you use an MSDN language? They're fairly simple and well documented (google searches are better than the msdn website, for navigation, usually)
I found this bit, and I couldn't tell you if it simulates keystrokes at a level close enough to the hardware, but it does appear to be able to generate keystroke events that other programs can recognize, which is what your ultimate goal is.
http://msdn.microsoft.com/en-us/library/ms171548.aspx
The 'Send' and 'SendWait' Methods seem to be the key ones.
http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.sendwait.aspx
Godspeed.
I'm not on a Windows box to test it against MouseKeys, so no guarantees that it will work, but have you tried AutoHotkey?
Related
Is there a way how to block keyboard input in java. I would like to catch the input in the java code, but stop it from being send to OS.
Example: i have notepad opened and i can write just fine, but when i press a combination of keys java app catches that input, and now i should not be able to write with my keyboard. Is this kind of behaviour possible?
I know how to capture key presses but the keyboard blocking part is a mystery to me.
I tried googling it but i did not find any solution.
You have to understand: java applications run with the JVM. A JVM isn't the operating system.
Therefore your ways to access resources belonging to the operating system are very limited.
In other words: there is no generic, cross plattform way of having a Java application being able to "intersect" arbitrary console user input for arbitrary other applications.
Imagine you are a person sitting in a bus - just a guy like everybody else. You have no authority to turn to fellow passengers and ask them for their passport or such things. You are just one guy in the bus, like everybody else. Same here: a Java application is lacking the means to control other processes.
As you are specifically asking about the Windows platform: there might be some options using JNI and specific native calls. See here for example.
So, to be precise: it is not possible in general, but depending on your operating system there might be ways, for example using JNI.
Yes, you can do this - I used this library:
https://github.com/tulskiy/jkeymaster
to successfully to register a "global" keyboard shortcut to open a window in my program that was running in the task tray.
You can't "stop" it from being sent to the OS, but you can register a keyboard shortcut, open your window, and give it focus, so that all other keystrokes go into that text box.
I need to connect more than one keyboard/mouse with a single computer. Manymouse library can identify different mouses, but is there a library which can identify different keyboards?
I mean, when I press Key "E", the program can tell me which keyboard the KeyPress event is from. With C#, the SDGToolkit can do it, is there something in the Java world or C world, which supports all OS just as Manymouse does? I am more interested in Mac and Linux solution.
Know the solution. I can use a hid library to detect different keyboard. Here is an explanation :
http://nanlee.wordpress.com/2013/06/12/manykeyboard-using-java-hid-api-to-handle-multiple-keyboard-input/
Is there a way to detect key input when the window is not active? That is, another application is running but the program is triggered when say the F9 key is pressed or something along those lines.
Is that possible or is java not compatible for such functions? From what I found java can't get input unless it's the active window.
Note:
I typically use keylistener, which seems to stop working (with good reason) when I am not actively using the program.
It sounds like you want low level keyboard hooks.
Get global keyboard input with Java
It's not directly possible in Java (i.e. with pure Java code), but you could reference other libraries (or make your own) to acheieve this. A quick google search gives a lot of references and free/open libraries that can give you keyboard and mouse hooks (both very handy).
Hope that helps.
I want to be able to record mouse movements, clicks and keyboard input from a user. It would be great if it was a cross platform solution.
I'd like to get back something like this (pseudo code):
mouse moved to 500, 500
mouse double clicked
mouse moved to 800, 300
mouse left clicked
keyboard typed "Hello World"
Does either C++ or Java have any classes that can do this? If I was using C++, I would probably working with the QT framework.
Edit:
I should have said this originally, but I want to record the movements and clicks outside of the applications gui, so on the desktop too.
GLUT does this, but it's tied to OpenGL which might be overkill for your project.
OpenGL is cross-platform.
I don't believe there's a cross-platform toolkit specifically for grabbing input from a window and nothing more, but most toolkits provide this capability. Two good options are:
Use SDL, as it's fairly lightweight and can handle simple input.
Implement the functionality natively per platform, as it should be trivial in X11, Windows, Mac OS X, etc.
On Windows, this is called a Journal Record Hook. You should write the hook part in C or C++, it might be technically possible to do in java, but it's not a good idea, you want your hook procedure to have as few dependencies as possible, and to be a quick as possible. System wide hooks, especially journal add a lot of overhead to keyboard and mouse input, you want to minized your impact as much as possible.
You Install Windows hooks by using SetWindowsHookEx passing WH_JOURNALRECORD to get a Journal Record Hook.
You could also (maybe) get this working by installing both WH_KEYBOARD_LL and WH_MOUSE_LL, but your two hook procedures would be called separately, and you would have to write your own code to put the events in order.
I doubt you will find a cross-platform solution.
It sounds like Qt might allow you to implement event filters that extend beyond the application to the window system. See also Qt - top level widget with keyboard and mouse event transparency?
If you want to trap events across the whole GUI system, not just one app, there's not much likelihood of a cross platform solution. However, the event hooking part could easily be separated from the recording part, so you could make most of the program cross-platform.
For Windows, you need this 17 year old (!) document. (Man, I'm getting old!)
A friend of mine asked me to implement a blue and a red pointer to represent the inputs of two separate mice to expedite a mixing desk scenario for real time audio mixing. I'd love to, but as much as I think it is a great idea, I don't have a clue as to where to start looking for a possible solution.
Where should I start researching a viable method of implementing dual mouse inputs?
Look at jinput.
I have had multiple keyboards working with it, I am nearly certain it supports multiple mice too.
dont know about java.. but for C#/c++ you can try the
Microsoft Windows MultiPoint Software Development Kit
i've tried it on windows.. it works with 2 USB mice.
It depends on which operating system you intend to use.
On Windows, you can use:
CPNMouse - a driver+software combination, very flexible and allows to completely hide some of the mice from the operating system.
RawInput - an API provided by Windows XP only. You can use it to distinguish between two mouse inputs, draw the cursors yourself and hide the main cursor. Take a look at the code of SDGT, a C# usage of this API.
For both solutions you would have to build a JNI bridge to your application
If you are using X.Org (X11) server, there is patched version called MPX that should support multiple mice even for legacy applications. It should now be a part of the X.Org trunk, but I'm not very familiar with it. Anyway it has an API so you can use it via JNI bridge.
You can use multiple devices, but at the Java level, all mouse events are coalesced into a single stream. The event does not include which mouse it came from. You did say you wanted to mix audio, right? Well this mix might be interesting, but surely not what you want.
I'd suggest using the Java-supported midi interface and connecting some simple midi controller device with multiple knobs or trackballs. These will come in as midi events, and you can examine the state for the details you need.