0

Canon SDK を使用してカメラからイベントを取得しています。SDK では、特定のイベントが発生したときに呼び出されるコールバック関数を登録します。SDK と通信する Java ラッパーを作成しました。

しかし、イベントがトリガーされると、ウィンドウはイベントを直接取得しません。実際、Windowsでは、これがイベントを取得して自分にディスパッチする方法です:

private static final User32 lib = User32.INSTANCE;
boolean hasMessage = lib.PeekMessage( msg, null, 0, 0, 1 ); // peek and remove
if( hasMessage ){
lib.TranslateMessage( msg ); 
lib.DispatchMessage( msg ); //message gets dispatched and hence the callback function is     called
}

基本的に、ウィンドウがイベントを受信したかどうかを確認してから続行します。Mac ではCocoa、NSApplication を使用してそれを行うことができ、WindowServerイベントがあれば送信します。

を使用して同様の代替手段を探していX11ます。サンプルコード/リンクで十分です。

PS:これはこれに対するフォローアップの質問です。

4

1 に答える 1

2

を探していると思いますXPeekEvent。Xlib は非常によく文書化されており、XNextEvent(3) のマンページには次のように書かれています。

The XPeekEvent function returns the first event from the event queue,
but it does not remove the event from the queue.  If the queue is
empty, XPeekEvent flushes the output buffer and blocks until an event
is received.  It then copies the event into the client-supplied XEvent
structure without removing it from the event queue.

イベントを処理するための基本的な Xwindow とメイン イベント ループを表示するためのサンプル コードは、(たとえば) wikibooks にあります。

于 2013-03-19T06:22:02.130 に答える