Application threading issue?
-
I'm not sure if this is the correct forum, but in case it's not, pls let me know where I can post for some assistance. I'm trying to write a program that supports the following requirements: Run while another program is running; Get the keyboard input(s) While on another program, my program will take the input and loop. In other words, instead of repeatedly pressing keys, if I hold key down, my program will loop and return the key value to the active screen. The problem I'm having right now, is that it works as a console, but when I switch to another screen, I loose focus of my application and the keyboard input is no longer being detected. I suspect I need help with threading but need some direction as well. Here's what I've got so far. #include <stdio.h> #include <conio.h> #include <iostream> using namespace std; //function prototypes void press_any_key(); void one(); void two(); void three(); int main(){ cout << "Start"; press_any_key(); getch(); return 0; } void press_any_key(){ bool done; done = true; char input; do{ do{ input = _getch(); if(input == '2'){ cout << "Currently holding the right key"; done = true; } else if(input == '+'){ cout << "Abort."; //done = true; exit(0); } else{ done = false; } }while (_kbhit()); }while(done == true); cout << "Done"; } Help pls. Thanks
-
I'm not sure if this is the correct forum, but in case it's not, pls let me know where I can post for some assistance. I'm trying to write a program that supports the following requirements: Run while another program is running; Get the keyboard input(s) While on another program, my program will take the input and loop. In other words, instead of repeatedly pressing keys, if I hold key down, my program will loop and return the key value to the active screen. The problem I'm having right now, is that it works as a console, but when I switch to another screen, I loose focus of my application and the keyboard input is no longer being detected. I suspect I need help with threading but need some direction as well. Here's what I've got so far. #include <stdio.h> #include <conio.h> #include <iostream> using namespace std; //function prototypes void press_any_key(); void one(); void two(); void three(); int main(){ cout << "Start"; press_any_key(); getch(); return 0; } void press_any_key(){ bool done; done = true; char input; do{ do{ input = _getch(); if(input == '2'){ cout << "Currently holding the right key"; done = true; } else if(input == '+'){ cout << "Abort."; //done = true; exit(0); } else{ done = false; } }while (_kbhit()); }while(done == true); cout << "Done"; } Help pls. Thanks
humblepgmr wrote:
Run while another program is running; Get the keyboard input(s) While on another program, my program will take the input and loop.
Sounds like a keyboard logger, normally used by hackers to steal passwords etc. We don't support hackers here on CodeProject.
led mike
-
humblepgmr wrote:
Run while another program is running; Get the keyboard input(s) While on another program, my program will take the input and loop.
Sounds like a keyboard logger, normally used by hackers to steal passwords etc. We don't support hackers here on CodeProject.
led mike
It's really not intended to be a key logger. I'll explain. I have a program that requires that I press the number '2' repeatedly; basically instead of pressing it manually, I'd like to just hold the button till I press the '+' key to terminate. While I agree that it can be saved somewhere as a file and then emailed / transfered over the network it's not my intended purpose. I really have a genuine need to press repteatedly. This isn't intended as an insult, but you jumped to a conclusion which is not accurate at all.