Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Application threading issue?

Application threading issue?

Scheduled Pinned Locked Moved Windows Forms
helpbusinessquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    humblepgmr
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • H humblepgmr

      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

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      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

      H 1 Reply Last reply
      0
      • L 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

        H Offline
        H Offline
        humblepgmr
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups