キーバインディングでxdotoolを実行するときの予期しない動作

キーバインディングでxdotoolを実行するときの予期しない動作

押すとxdotoolが実行されるキーを作成しました。ただし、不明な理由から、xdotoolはバインドされたキーを離したときにのみキーストロークを送信します。ただし、非アクティブウィンドウのキーストロークを送信するために--windowを使用しない限り、この場合(アクティブウィンドウに対して必要に応じて)は、次の場合にキーストロークを送信します。バウンドキーが押され、押し続けると繰り返し発生します。

問題のあるサンプルコード:

#include <stdio.h>
#include <stdlib.h>
#include <xcb/xcb.h>

int main() {
    xcb_connection_t *connection = xcb_connect(NULL, NULL);

    xcb_screen_t *screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;

    xcb_grab_key(connection, 1, screen->root, XCB_NONE, 65, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);  // 65=space (on mine at least)

    xcb_flush(connection);

    xcb_generic_event_t *event;
    while ( (event = xcb_wait_for_event(connection)) ) {
        switch (event->response_type & ~0x80) {
            case XCB_KEY_PRESS: {

                // UNCOMMENT ONE OF THE LINES BELOW
                // system("xdotool key q");  // only on release :(
                // system("xdotool getactivewindow key --window %1 q");  // only on release :(
                // system("xdotool key --window 18874376 q");  // (replace 18874376 with one of your window's id, could use 'xdotool getactivewindow') works perfectly for me but only if the specified window is not active :(

                break;
            }
        }
        free(event);
    }
}

上記はNum Lockを含む修飾子には適用されません。

コンパイル:

gcc c.c -lxcb

あなたも同じ経験をしたことがありますか?私が欲しいものをどのように得ることができますか?

ベストアンサー1

おすすめ記事