Advertisement
agrippa1994

adsfg

Aug 6th, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <algorithm>
  4. #include <functional>
  5.  
  6. #include <boost/thread.hpp>
  7. #include <boost/bind.hpp>
  8. #include <boost/date_time.hpp>
  9.  
  10. using namespace std;
  11.  
  12. int x = 0;
  13. boost::mutex mtx;
  14.  
  15. queue<char> keys;
  16.  
  17. bool acceptKeys = true ;
  18. // Visual Basic Funktion
  19. void vbFunc(char c){
  20.  
  21.     cout << "VB start: " << (int)c << endl;
  22.     boost::this_thread::sleep_for(boost::chrono::milliseconds(20));
  23.     cout << "VB end: " << (int)c << endl;
  24. }
  25.  
  26.  
  27. struct{
  28.     bool AddBlockKey(char c){
  29.         auto it = find_if(_blocked_keys.begin(),_blocked_keys.end(),[&](char key){ return key == c; });
  30.         if(it != _blocked_keys.end()) return false;
  31.  
  32.         _blocked_keys.push_back(c);
  33.         return true;
  34.     }
  35.  
  36.     bool DeleteBlockedKey(char c){
  37.         auto it = find_if(_blocked_keys.begin(),_blocked_keys.end(),[&](char key){ return key == c; });
  38.         if(it == _blocked_keys.end()) return false;
  39.  
  40.         _blocked_keys.erase(it);
  41.         return true;
  42.     }
  43.  
  44.     bool IsBlockedKey(char c){
  45.         auto it = find_if(_blocked_keys.begin(),_blocked_keys.end(),[&](char key){ return key == c; });
  46.         if(it == _blocked_keys.end()) return false;
  47.         return true;
  48.     }
  49.  
  50. private:
  51.     vector<char>    _blocked_keys;
  52. }
  53.  
  54. Blocked;
  55.  
  56.  
  57. int main(){
  58.  
  59.     Blocked.AddBlockKey(5);
  60.  
  61.     for(char i=0;i<10;i++){
  62.         // Keyboard Hook
  63.         boost::this_thread::sleep_for(boost::chrono::milliseconds(0));
  64.  
  65.         // Wird vom OS aufgerufen
  66.         auto keyProc = [&](char key) -> bool
  67.         {
  68.             //KeyInfo.Add(key);
  69.             boost::thread(vbFunc,key);
  70.             // 1 wenn Blockiert
  71.             // 0 wenn durchlassen
  72.  
  73.             return Blocked.IsBlockedKey(key);
  74.         };
  75.  
  76.  
  77.  
  78.         // Böses OS
  79.         if(keyProc(char(i)))
  80.             cout << "Blockierter Key: " << (int)i << endl;
  81.         else
  82.             cout << "Key durchgelassen: " << (int)i << endl;
  83.  
  84.     }
  85.  
  86.     cout << "Threads gestartet" << endl;
  87.  
  88.     while(1) boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
  89.  
  90.     getchar();
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement