Domanda

I have this bit of code which uses SendInput to send a key press but it doesn't work for when I want to long hold a key (eg long hold 'a' would return 'aaaaaaaaa' in notepad).

Now I have looked all over google and the only way I can see to get around this is to keep sending the input if I want a long hold. I don't want to do that as this will just simulate 'a' being pressed over and over again.

keyboard.wVk = 0;
keyboard.wScan = MapVirtualKey(key, 0);

keyboard.dwFlags = KEYEVENTF_SCANCODE;

if (index_vector_no)
    pressed[index_vector_no] = true;

keyboard.dwExtraInfo = 0;

input.type = INPUT_KEYBOARD;
input.ki = keyboard;

SendInput(1, &input, sizeof (input));

So I would like some answers to the following questions:

A) Am I right in thinking there is no way around this using SendInput and why doesn't it work for long hold?

B) What is an alternative method for successfully being able to send key down and key up signals. Preferably sending the keys to windows and not just to a particular application.

C) Is there a good lightweight C++ library I can use that handles global keyboard and mouse simulation?

Thanks in advance! =)

EDIT: Take a look at this post for more details of my problem: http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20833788.html

È stato utile?

Soluzione

Repeating keystrokes is a feature of the keyboard controller, not of Windows or SendInput. You can certainly emulate it with a timer, repeatedly calling SendInput().

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top