Coder Social home page Coder Social logo

qtglobalinput's Introduction

QtGlobalInput

QtGlobalInput is small library that implements windows global hooks in Qt.

Structure

All funktions in QtGlobalInput are static and should be called with

QtGlobalInput::functionName()

Init and deinitialize

Initialization

Before creating hooks, QtGlobalInput must be initialized with

QtGlobalInput::init(hwnd)

Example:

QtGlobalInput::init((HWND)MainWindow::winId());

Deinitialization

If you don't need hooks anymore, you can deinialize QtGlobalInput with

QtGlobalInput::deinitialize()

Set

All funktions are returning hook id. With this id hook can be removed.

EventType

enum class EventType
{
    All,
    ButtonDown,
    ButtonUp
};

setLlKeyboardHook

static uint setLlKeyboardHook(uint vkCode, EventType type, A callback, B obj, bool async = false);
  1. vkCode - vkCode of the key you want to hook. If vkCode is 0, will hook all key presses
  2. type - decides if should listen to key down or key up
  3. callback - funktion that will be called when hook triggers. Should have form:
void function(int nCode, WPARAM wParam, LPARAM lParam)
  1. obj - object that has callback funktion
  2. async - if true, callback funktion will be called asynchronous

waitForKeyPress

static uint waitForKeyPress(uint vkCode, EventType type, A callback, B obj, bool async = false);
  1. vkCode - vkCode of the key you want to hook. If vkCode is 0, will hook all key presses
  2. type - decides if should listen to key down or key up
  3. callback - funktion that will be called when hook triggers. Should have form:
void function(RAWKEYBOARD rawkeyboard)
  1. obj - object that has callback funktion
  2. async - if true, callback funktion will be called asynchronous

wairForMousePress

static uint waitForMousePress(uint vkCode, EventType type, A callback, B obj, bool async = false);
  1. vkCode - vkCode of the key you want to hook. If vkCode is 0, will hook all key presses
  2. type - decides if should listen to key down or key up
  3. callback - funktion that will be called when hook triggers. Should have form:
void function(RAWMOUSE rawmouse)
  1. obj - object that has callback funktion
  2. async - if true, callback funktion will be called asynchronous

setWindowSwitch

static uint setWindowSwitch(A callback, B obj)
  1. callback - funktion that will be called when hook triggers. Should have form - void function(HWND hwnd)
  2. obj - object that has callback funktion

Remove

This funktions will remove hook by his id and return true if hook is successfully deleted.

1. static bool removeLlKeyboardHook(uint id);
2. static bool removeKeyPress(uint id);
3. static bool removeMousePress(uint id);
4. static bool removeWindowSwitch(uint id);

Example

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
  ui->setupUi(this);
  QtGlobalInput::init((HWND)MainWindow::winId());
  uint keyPressId = QtGlobalInput::waitForKeyPress(0, EventType::ButtonUp, &MainWindow::handleKey, this, true);
  uint windowSwitchId = QtGlobalInput::setWindowSwitch(&MainWindow::windowSwitched, this);
}

void MainWindow::windowSwitched(HWND hwnd) { ... }

void MainWindow::handleKey(RAWKEYBOARD keyboard) { ... }

qtglobalinput's People

Contributors

qyqymba avatar

Watchers

 avatar

Forkers

lzhice

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.