Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 26th, 2004, 10:14 AM   #1
Johnny_English
Newbie
 
Join Date: Sep 2004
Posts: 7
Rep Power: 0 Johnny_English is on a distinguished road
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?
Johnny_English is offline   Reply With Quote
Old Oct 27th, 2004, 12:09 AM   #2
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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
kurifu is offline   Reply With Quote
Old Oct 27th, 2004, 12:10 AM   #3
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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
kurifu is offline   Reply With Quote
Old Oct 27th, 2004, 10:38 AM   #4
Johnny_English
Newbie
 
Join Date: Sep 2004
Posts: 7
Rep Power: 0 Johnny_English is on a distinguished road
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:
Johnny_English is offline   Reply With Quote
Old Oct 27th, 2004, 12:00 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Replace the loop with a Timer - that way it won't hog all the program resources.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Oct 27th, 2004, 11:57 PM   #6
Johnny_English
Newbie
 
Join Date: Sep 2004
Posts: 7
Rep Power: 0 Johnny_English is on a distinguished road
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?
Johnny_English is offline   Reply With Quote
Old Oct 28th, 2004, 6:07 AM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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++.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC