是否可以禁用或禁止诸如打印屏幕键之类的键?
我的事件filter:
bool EventFilter::eventFilter(QObject *object,QEvent *event) { qDebug() << "object:" << object << "type:" << event->type(); return false; }
我尝试在qApp使用:
ui->setupUi(this); EventFilter *evt = new EventFilter; qApp->installEventFilter(evt);
但是只返回来自应用程序小部件的事件:
Java作为Windows服务与交互式桌面支持和读取currenlogin用户
在Linux中以编程方式在C中检测桌面环境
如何从Windows资源pipe理器(在任何编程语言,借助任何工具)inheritance
如何编写Windows应用程序来更改桌面壁纸?
被要求使用Selenium来testingWindows桌面应用程序界面 – 这怎么可能?
object: QWidgetwindow(0x175bae50,name = "QWidgetClassWindow") type: QEvent::Type(PlatformSurface) object: QWidget(0x175b02c0) type: QEvent::Type(PlatformSurface) object: QWidget(0x175b02c0) type: QEvent::Type(WinIdChange) object: QWidget(0x175b02c0) type: QEvent::Type(Create) ...
和:
ui->setupUi(this); EventFilter *evt = new EventFilter; QDesktopWidget *c = new QDesktopWidget; c->installEventFilter(evt);
但是只返回2个事件:
object: QDesktopWidget(0x174e0260,name = "desktop") type: QEvent::Type(PolishRequest) object: QDesktopWidget(0x174e0260,name = "desktop") type: QEvent::Type(Polish)
不能拦截和/或阻止事件? 谢谢
在没有窗口的Windows桌面上绘制OpenGL
基于linuxterminal的桌面
Java 1.6和Desktop.open()的问题
如何扩展Windows桌面searchla Outlook
您可以安装一个低级别的键盘挂钩来拦截和屏蔽所有的Print Screen印刷机。 以下是我的Windows 7机器上测试。
这是一个简单的例子,展示了如何做到这一点:
#include <QtWidgets> #include <windows.h> //link against user32.lib when compiling in MSVC #ifdef _MSC_VER #pragma comment(lib,"User32.lib") #endif class GlobalPrintScreenBlocker { public: GlobalPrintScreenBlocker():mHKeyboardHook(NULL) {} //to avoid leaking the hook procedure handle ~GlobalPrintScreenBlocker(){ unblock(); } //hook callback function (called on every system-wide key press) static LRESULT CALLBACK LowLevelKeyboardProc(int nCode,WParaM wParam,LParaM lParam) { if(nCode == HC_ACTION) { PKBDLLHOOKSTRUCT p = reinterpret_cast<PKBDLLHOOKSTRUCT>(lParam); if(p->vkCode == VK_SNAPSHOT) return 1; //block print-screen key } //this is not a message we are interested in return CallNextHookEx(NULL,//ignored paramater nCode,wParam,lParam); } void block(){ mHKeyboardHook = SetwindowsHookEx(WH_KEYBOARD_LL,//low-level keyboard hool &LowLevelKeyboardProc,//callback GetmoduleeHandle(NULL),0); } void unblock(){ if(mHKeyboardHook) UnhookWindowsHookEx(mHKeyboardHook); mHKeyboardHook = NULL; } private: HHOOK mHKeyboardHook; }; int main(int argc,char* argv[]) { QApplication a(argc,argv); GlobalPrintScreenBlocker blocker; QPushButton button("disable ScreenShot"); button.setCheckable(true); QObject::connect(&button,&QPushButton::toggled,[&](bool isChecked){ if(isChecked) blocker.block(); else blocker.unblock(); }); button.show(); return a.exec(); }
钩子在安装它的线程中被调用。 这样做的优点是不必担心回调函数中的线程安全问题,并且在32位进程和64位进程之间没有区别(所有进程最终都会通过发布消息到安装钩子的线程的事件循环)。 但是,这也有一个缺点,如果你的线程忙(执行其他任何事情)回调挂钩可能不会被调用:
挂钩过程应该在比LowLevelHooksTimeout值中指定的数据条目更少的时间内处理消息…该值以毫秒为单位。 如果挂钩程序超时,系统将消息传递给下一个挂钩。 但是,在Windows 7和更高版本中,挂钩将被静默移除而不被调用。 应用程序无法知道挂钩是否被移除。
你可以通过分配一个单独的线程来安装/执行钩子来解决这个限制。 此外,请注意您的钩子的回调函数应尽可能最小,以便能够在时间限制内完成。
PS:我不得不使用剪切工具来创建上面的屏幕截图。 。 。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。