Computer Science Canada Start/Stop function using getch |
Author: | Cancer Sol [ Tue Apr 02, 2013 10:55 am ] | ||
Post subject: | Start/Stop function using getch | ||
I'm not sure if I shouldn't use conio.h, but I did so I could use the getch function. Basically, this is a part of my auto-clicker, and if the user pressed three, it'll start the clicking, and if they press three again, it'll stop clicking.
Does anyone know how to make it stop if I press three, and make it pause even if the console window isn't highlighted? |
Author: | nullptr [ Tue Apr 02, 2013 3:48 pm ] | ||
Post subject: | Re: Start/Stop function using getch | ||
Cancer Sol @ Tue Apr 02, 2013 10:55 am wrote: I'm not sure if I shouldn't use conio.h, but I did so I could use the getch function.
Basically, this is a part of my auto-clicker, and if the user pressed three, it'll start the clicking, and if they press three again, it'll stop clicking.
Does anyone know how to make it stop if I press three, and make it pause even if the console window isn't highlighted? As far as I know, the only way to get what you want is to use threads. See http://en.cppreference.com/w/cpp/thread/thread -- you'll need an up-to-date compiler like gcc 4.7. Otherwise, you'd need to wait for user input between each mouse click. |
Author: | Cancer Sol [ Tue Apr 02, 2013 5:11 pm ] | ||
Post subject: | Re: Start/Stop function using getch | ||
nullptr @ 4/2/2013, 3:48 pm wrote: Cancer Sol @ Tue Apr 02, 2013 10:55 am wrote: I'm not sure if I shouldn't use conio.h, but I did so I could use the getch function.
Basically, this is a part of my auto-clicker, and if the user pressed three, it'll start the clicking, and if they press three again, it'll stop clicking.
Does anyone know how to make it stop if I press three, and make it pause even if the console window isn't highlighted? As far as I know, the only way to get what you want is to use threads. See http://en.cppreference.com/w/cpp/thread/thread -- you'll need an up-to-date compiler like gcc 4.7. Otherwise, you'd need to wait for user input between each mouse click. Will the GNU-GCC compiler that's included with Code Blocks MingW recognize it? |
Author: | Insectoid [ Tue Apr 02, 2013 7:16 pm ] |
Post subject: | RE:Start/Stop function using getch |
It's a library. You install it and include it and it will work. On Windows. Some libraries only work on a specific operating system or architecture. conio.h is one of them. |
Author: | nullptr [ Tue Apr 02, 2013 9:50 pm ] | ||
Post subject: | Re: Start/Stop function using getch | ||
Cancer Sol @ Tue Apr 02, 2013 5:11 pm wrote: nullptr @ 4/2/2013, 3:48 pm wrote: Cancer Sol @ Tue Apr 02, 2013 10:55 am wrote: . . . As far as I know, the only way to get what you want is to use threads. See http://en.cppreference.com/w/cpp/thread/thread -- you'll need an up-to-date compiler like gcc 4.7. Otherwise, you'd need to wait for user input between each mouse click. Will the GNU-GCC compiler that's included with Code Blocks MingW recognize it? I'm not sure what version is included. Try this code and see if it works:
Insectoid wrote: It's a library. You install it and include it and it will work. On Windows. Some libraries only work on a specific operating system or architecture. conio.h is one of them. Isn't thread platform-independent and installed by default, as part of the STL? Or were you talking specifically about conio.h? |
Author: | Cancer Sol [ Wed Apr 03, 2013 1:06 pm ] | ||||
Post subject: | Re: Start/Stop function using getch | ||||
nullptr @ 4/2/2013, 9:50 pm wrote: Cancer Sol @ Tue Apr 02, 2013 5:11 pm wrote: nullptr @ 4/2/2013, 3:48 pm wrote: Cancer Sol @ Tue Apr 02, 2013 10:55 am wrote: . . . As far as I know, the only way to get what you want is to use threads. See http://en.cppreference.com/w/cpp/thread/thread -- you'll need an up-to-date compiler like gcc 4.7. Otherwise, you'd need to wait for user input between each mouse click. Will the GNU-GCC compiler that's included with Code Blocks MingW recognize it? I'm not sure what version is included. Try this code and see if it works:
Insectoid wrote: It's a library. You install it and include it and it will work. On Windows. Some libraries only work on a specific operating system or architecture. conio.h is one of them. Isn't thread platform-independent and installed by default, as part of the STL? Or were you talking specifically about conio.h? Alright, I'll try it right after, but what does join for t.join do? Edit: Nope, won't work.
|
Author: | nullptr [ Wed Apr 03, 2013 5:08 pm ] | ||||
Post subject: | Re: Start/Stop function using getch | ||||
Cancer Sol @ Wed Apr 03, 2013 1:06 pm wrote: nullptr @ 4/2/2013, 9:50 pm wrote: Cancer Sol @ Tue Apr 02, 2013 5:11 pm wrote: nullptr @ 4/2/2013, 3:48 pm wrote: Cancer Sol @ Tue Apr 02, 2013 10:55 am wrote: . . . As far as I know, the only way to get what you want is to use threads. See http://en.cppreference.com/w/cpp/thread/thread -- you'll need an up-to-date compiler like gcc 4.7. Otherwise, you'd need to wait for user input between each mouse click. Will the GNU-GCC compiler that's included with Code Blocks MingW recognize it? I'm not sure what version is included. Try this code and see if it works:
Insectoid wrote: It's a library. You install it and include it and it will work. On Windows. Some libraries only work on a specific operating system or architecture. conio.h is one of them. Isn't thread platform-independent and installed by default, as part of the STL? Or were you talking specifically about conio.h? Alright, I'll try it right after, but what does join for t.join do? Edit: Nope, won't work.
You'll have to find the setting for compiler arguments in Code::Blocks and add -std=c++11. t.join() waits for the thread to finish before continuing. If your main thread exits before a child thread, it will cause a mysterious error. |
Author: | Cancer Sol [ Wed Apr 03, 2013 7:31 pm ] | ||||||||
Post subject: | Re: Start/Stop function using getch | ||||||||
nullptr @ 4/3/2013, 5:08 pm wrote: Cancer Sol @ Wed Apr 03, 2013 1:06 pm wrote: nullptr @ 4/2/2013, 9:50 pm wrote: Cancer Sol @ Tue Apr 02, 2013 5:11 pm wrote: nullptr @ 4/2/2013, 3:48 pm wrote: Cancer Sol @ Tue Apr 02, 2013 10:55 am wrote: . . . As far as I know, the only way to get what you want is to use threads. See http://en.cppreference.com/w/cpp/thread/thread -- you'll need an up-to-date compiler like gcc 4.7. Otherwise, you'd need to wait for user input between each mouse click. Will the GNU-GCC compiler that's included with Code Blocks MingW recognize it? I'm not sure what version is included. Try this code and see if it works:
Insectoid wrote: It's a library. You install it and include it and it will work. On Windows. Some libraries only work on a specific operating system or architecture. conio.h is one of them. Isn't thread platform-independent and installed by default, as part of the STL? Or were you talking specifically about conio.h? Alright, I'll try it right after, but what does join for t.join do? Edit: Nope, won't work.
You'll have to find the setting for compiler arguments in Code::Blocks and add -std=c++11. t.join() waits for the thread to finish before continuing. If your main thread exits before a child thread, it will cause a mysterious error. Oh, I see. But why does this:
Has the function test in it anyways? Is the output
|
Author: | nullptr [ Wed Apr 03, 2013 8:32 pm ] | ||||||
Post subject: | Re: Start/Stop function using getch | ||||||
Quote: Oh, I see. But why does this:
Has the function test in it anyways? Is the output
When you construct a thread like that, you're telling the program to execute the function given, but in another thread (you can pass arguments to that function by giving them to the thread constructor). Both that thread and the current thread will execute at the same time -- so the output could be what you put, but it could also be
and in fact, the output might vary as you run the program multiple times. Try this tutorial: http://www.codeproject.com/Articles/14746/Multithreading-Tutorial[/quote] |