Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <chrono>
- char keyboardCheck() {
- using namespace std::chrono;
- char controls[] = { 'W','S','A','D','E','Q','R'};
- char keyToCheck = 0;
- static char lockedKey;
- static steady_clock::time_point start;
- steady_clock::time_point end;
- int tick = 200;
- bool iWantToMove = false;
- for (short i = 0; i < sizeof(controls) / sizeof(char); i++) {
- if (GetAsyncKeyState(controls[i])) {
- if (keyToCheck != 0) return 0;
- keyToCheck = controls[i];
- }
- }
- end = steady_clock::now();
- if (keyToCheck == 'W' || keyToCheck == 'S' || keyToCheck == 'A' || keyToCheck == 'D')
- iWantToMove = true;
- if (duration_cast<milliseconds>(end - start).count() > tick && iWantToMove) lockedKey = 0;
- if (keyToCheck != lockedKey) {
- start = steady_clock::now();
- lockedKey = keyToCheck;
- return keyToCheck;
- }
- else return 0;
- }
- int main(){
- while(true) {
- char click = keyboardCheck();
- if(click) std::cout << click;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement