TChatzigiannakis / InputSimulatorPlus

Windows Input Simulator Plus
Microsoft Public License
94 stars 26 forks source link

(Enhancement) Option to "eat" key #8

Open jigglyDiggly opened 6 years ago

jigglyDiggly commented 6 years ago

Hey there,

can you please add an option like

private bool showKey = false; public void EatKey(bool eat) => showKey = !eat;

and depending of the value of showKey either process it to the target or dont process it? Or can you tell me, where exactly the key processing can be interrupted in your code?

I want to use it to rebind keys in old games, so when i press "W" it should simulate "↑" without processing the "W" Key to the game.

TChatzigiannakis commented 6 years ago

Thank you for your feedback!

If I'm understanding this correctly, you want this library to rebind keys so that when you press a particular physical key, the library stops that signal and instead sends a virtual keystroke for another key. Is that correct?

Although this is an interesting feature, I should remind that this library merely creates virtual key strokes, it doesn't actively watch the queue, nor does it remove other keystrokes from the queue, if that's possible at all.

I'll definitely look into it whether it's doable and how.

jigglyDiggly commented 6 years ago

Thank you for the answer. Yes, that's exactly what I'm going to do. To realize this I have a low-level KeyHook in the project to intercept the keys. Somehow I got mixed up with all the classes and thought it was from your project. I guess I was wrong.

But if you can think of a way to implement this, I would be very grateful :)

Here's the class that works so far that the pressed key is intercepted. Unfortunately I don't see any possibility to suppress the pressed key at the moment, because either all (pressed key + inputSimulator.TextEntry) or none are passed through.

Class Core ` hook = new GlobalKeyboardHook();

hook.KeyUp += Hook_KeyUp;

hook.KeyDown += Hook_KeyDown;

Dictionary<int, string> key2Press_Text = new Dictionary<int, string>(); //dictionary with key,text to simulate

KeyboardSimulator inputSimulator = new KeyboardSimulator(new InputSimulator());

GlobalKeyboardHook hook = new GlobalKeyboardHook();

Public Core() {hook.Install();} ... private bool Hook_KeyDown(GlobalKeyboardHook.VKeys key) { if (key2Press_Text.ContainsKey((int)key)) { SendText(key2Press_Text[(int)key]); return true; } return false; }` Class GlobalKeyboardHook https://pastebin.com/j89gNa8P

TChatzigiannakis commented 5 years ago

@jigglyDiggly Hi. I've looked into the issue after all and realized that this feature would be nice to have, after all. I can't say when I'll start working on it, and I need to take some time to think about the API first, but I'm generally positive about it.

jigglyDiggly commented 5 years ago

@TChatzigiannakis Thank's for your reply. Ive got some GUI and classes you can maybe use i think. In general, my solution works fine except the point, that i am not able to "eat" the pressed keys and then go on writing all other keys. My tries are in class GlobalKeyHook.cs line 229/281/282 in combination witch Class Core.cs line 68/70 & 96/98. Do you have got any idea how to suppress the key(combination) from beeing outputted without removing anything?

QuickRecruiter.zip(no .exe included, only project files and source code)

p.s. in case you try out the HoocFunc in class GlobalKeyHook.cs, be sure to have taskmanager opened and visible. Once you are in rapped in "return (IntPtr)1;" you are unable to press strg+alt+entf or any other key combination at all