Вопрос

I have written an On Screen Keyboard using firemonkey.

enter image description here

I simulate key events with this code:

void kbdEvent(unsigned int key, int modifiers)
{
    ::CGEventSourceRef source =
        CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
    ::CGEventRef keyDown = CGEventCreateKeyboardEvent(source,
        (::CGKeyCode)key, true);
    ::CGEventRef keyUp = CGEventCreateKeyboardEvent(source, (::CGKeyCode)key,
        false);
    CGEventSetFlags(keyDown, modifiers);
    CGEventPost(kCGHIDEventTap, keyDown);
    CGEventPost(kCGHIDEventTap, keyUp);
    CFRelease(keyUp);
    CFRelease(keyDown);
    CFRelease(source);
}

The problem is that when I press a key then my form receives focus and the generated event is not received by target app. If I put the following code in a timer there is no problem and the 'a' will typed in any editable target:

kbdEvent(kVK_ANSI_A, 0);

How can I do it without receive focus?

Это было полезно?

Решение

What you need to make an OSK is a No Activate Form. See the most popular firemonkey question.
A "No Activate" window does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top