![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2004
Posts: 7
Rep Power: 0
![]() |
I have this program where something needs to be done throughout the entire program. I also though need the program to accept keyboard inputs. I have the keyboard input function working, but if I use a for loop it never runs because the loop is always running. I tried accomplishing the task recursively but ran out of stack space
. I was wondering if mabey I could use threads, or is there some function to poll the keyboard I could run in the loop to see if a key has been pressed? |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Why not just use your windows callback to check for keyboard activity? If you have something happening that is preventing your windows message queue from being checked you are likely making a very fatal error with your program flow which will result in your application likely crashing when the messaging queue becomes too large.
Perhaps that is a bit of speculation, but the messaging queue IS MEANT TO BE CHECKED! WM_KEYBOARD should be sent when keyboard activity occures, or something like that... could be WM_KEY (look through MSDN to verify which one it is). If by chance you are blocking the message queue than you need to move your calculation to a seperate thread, especially if that process should never be interrupted during the execution of your application.... but if it is running in a loop, than there is no reason you can not check your message queue at some point in the loop... just PeekMessage to see if anything is there, and GetMessage until there are no messages left if something is there. PeekMessage polls the message queue... so it is not like it is going to block your application from executing.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#3 |
|
Expert Programmer
|
Oh yeah, and function names may vary a little bit (likely not) since I am a C++ windows programmer, not VB
![]()
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Sep 2004
Posts: 7
Rep Power: 0
![]() |
Can you please clarify? Every time I try to implement threads the program crashed. Furthermore, I don't see how your solution could work.
This is part of a pong game and I'm trying to handle both the ball moving function (which uses vectors and the tag property), and the paddle moving function. Both of these work well independently, but together the loop which handles the ball's motion superceeds all keyboard input, making the game unachievable. <_< ¿Please help? :unsure: |
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Replace the loop with a Timer - that way it won't hog all the program resources.
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Sep 2004
Posts: 7
Rep Power: 0
![]() |
You mean that while a timer sleeps the computer can receive input and execute based on that input?
How would I make the process repeat? |
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Set the timer to Enabled, with an interval of 33 (that's near enough 30fps). Then put the code to write one frame in the timer. It'll run every 33ms, and the rest of the code will run the rest of the time. This is also great for frame-locking. However, if you really want to get into games, learn C++.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|