• 4224阅读
  • 3回复

如何实现键盘监视功能? [复制链接]

上一主题 下一主题
离线solomoon
 
只看楼主 倒序阅读 楼主  发表于: 2009-08-06
让一个后台程序记录 其他qt程序接收的按键值?
离线duduqq

只看该作者 1楼 发表于: 2009-08-07
void QWidget::keyPressEvent ( QKeyEvent * event )   [virtual protected]

This event handler, for event event, can be reimplemented in a subclass to receive key press events for the widget.

A widget must call setFocusPolicy() to accept focus initially and have focus in order to receive a key press event.

If you reimplement this handler, it is very important that you call the base class implementation if you do not act upon the key.

The default implementation closes popup widgets if the user presses Esc. Otherwise the event is ignored, so that the widget's parent can interpret it.

Note that QKeyEvent starts with isAccepted() == true, so you do not need to call QKeyEvent::accept() - just do not call the base class implementation if you act upon the key.

See also keyReleaseEvent(), setFocusPolicy(), focusInEvent(), focusOutEvent(), event(), QKeyEvent, and Tetrix Example.

void QWidget::keyReleaseEvent ( QKeyEvent * event )   [virtual protected]

This event handler, for event event, can be reimplemented in a subclass to receive key release events for the widget.

A widget must accept focus initially and have focus in order to receive a key release event.

If you reimplement this handler, it is very important that you call the base class implementation if you do not act upon the key.

The default implementation ignores the event, so that the widget's parent can interpret it.

Note that QKeyEvent starts with isAccepted() == true, so you do not need to call QKeyEvent::accept() - just do not call the base class implementation if you act upon the key.

See also keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(), focusInEvent(), focusOutEvent(), event(), and QKeyEvent.
离线solomoon
只看该作者 2楼 发表于: 2009-08-07
根据楼上兄的线索,翻了下文档,发现这个才是正解

bool QApplication::qwsEventFilter ( QWSEvent * event )   [virtual]

This virtual function is only implemented under Qt for Embedded Linux.

If you create an application that inherits QApplication and reimplement this function, you get direct access to all QWS (Q Window System) events that the are received from the QWS master process. The events are passed in the event parameter.

Return true if you want to stop the event from being processed. Return false for normal event dispatching. The default implementation returns false.
离线cspp

只看该作者 3楼 发表于: 2009-08-07
Win32下可以用钩子,
Unix下可以用XGrab
快速回复
限100 字节
 
上一个 下一个