Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <algorithm>
- #include <functional>
- #include <boost/thread.hpp>
- #include <boost/bind.hpp>
- #include <boost/date_time.hpp>
- using namespace std;
- int x = 0;
- boost::mutex mtx;
- queue<char> keys;
- bool acceptKeys = true ;
- // Visual Basic Funktion
- void vbFunc(char c){
- cout << "VB start: " << (int)c << endl;
- boost::this_thread::sleep_for(boost::chrono::milliseconds(20));
- cout << "VB end: " << (int)c << endl;
- }
- struct{
- bool AddBlockKey(char c){
- auto it = find_if(_blocked_keys.begin(),_blocked_keys.end(),[&](char key){ return key == c; });
- if(it != _blocked_keys.end()) return false;
- _blocked_keys.push_back(c);
- return true;
- }
- bool DeleteBlockedKey(char c){
- auto it = find_if(_blocked_keys.begin(),_blocked_keys.end(),[&](char key){ return key == c; });
- if(it == _blocked_keys.end()) return false;
- _blocked_keys.erase(it);
- return true;
- }
- bool IsBlockedKey(char c){
- auto it = find_if(_blocked_keys.begin(),_blocked_keys.end(),[&](char key){ return key == c; });
- if(it == _blocked_keys.end()) return false;
- return true;
- }
- private:
- vector<char> _blocked_keys;
- }
- Blocked;
- int main(){
- Blocked.AddBlockKey(5);
- for(char i=0;i<10;i++){
- // Keyboard Hook
- boost::this_thread::sleep_for(boost::chrono::milliseconds(0));
- // Wird vom OS aufgerufen
- auto keyProc = [&](char key) -> bool
- {
- //KeyInfo.Add(key);
- boost::thread(vbFunc,key);
- // 1 wenn Blockiert
- // 0 wenn durchlassen
- return Blocked.IsBlockedKey(key);
- };
- // Böses OS
- if(keyProc(char(i)))
- cout << "Blockierter Key: " << (int)i << endl;
- else
- cout << "Key durchgelassen: " << (int)i << endl;
- }
- cout << "Threads gestartet" << endl;
- while(1) boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement