#ifndef MODETHREAD_H
#define MODETHREAD_H

#include <QThread>
#include <windows.h>

class ModeThread : public QThread
{
    Q_OBJECT
public:
    ModeThread(){}
    void setMode(int m){ mode = m; }

private:
    int mode = 0;  // 0 - on/off, 1 - on, 2 - off
    void press() {
        keybd_event(VK_NUMLOCK, 0, KEYEVENTF_KEYUP, 0);
        keybd_event(VK_NUMLOCK, 0, KEYEVENTF_EXTENDEDKEY, 0);
        keybd_event(VK_NUMLOCK, 0, KEYEVENTF_KEYUP, 0);
    }

protected:
    void run() override{
        forever{
            if (mode == 0) return;
            if (mode == 1 && !(bool)GetKeyState(VK_NUMLOCK))
                    press();
            if (mode == 2 && (bool)GetKeyState(VK_NUMLOCK))
                    press();
            msleep(100);
        }
    }
};

#endif // MODETHREAD_H
