Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Keyboard and Mouse

Author
Message
WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 24th Mar 2009 02:51
You use the dbWaitKey() function to pause the program until a key is pressed. You use the dbWaitMouse() function to pause the program until a mouse button is clicked. Is there any function that will pause the program until either a key or a mouse button is pressed? If the answer is no, then is there a way to create a program that will accept a key or a mouse click at any given time? I am creating a tic tac toe game. I want to make it so that left-clicking will place an X or an O on screen and if the user decides to not place an X or an O, the other input that the program will accept is the pressing of the escape key to open a menu that asks the user if he/she wishes to end the game. Is there a way to do this? I am sure there is or else how is it possible that the creators of FPS games are able to create programs that respond when the user presses the W, A, S, D keys and also respond when the user left-clicks on his.her mouse to shoot?
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 24th Mar 2009 23:46
Unfortunately this is not possible and never will be.

WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 25th Mar 2009 00:02
What is not possible? Pausing the program until either a key or a mouse button is pressed or not being able to create a program that can respond to either a key or a mouse button at any one time? If you say both, then how do the creators of FPS games able to create a program that can respond to either a key or a mouse button press at any one time? When you are playing FPS games, you can input using the mouse as well as input using the keyboard at any one time. This allows you to press the space key to jump at any time and during the times when you are able to press space to jump, you can also left-click the mouse button to shoot. As you can see, FPS games are programs that can respond to either a key or mouse button press at any one time.
heyufool1
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location: My quiet place
Posted: 25th Mar 2009 01:33
I'm kinda confused on your question. In your first question you ask if you can pause the game until a mouse or keyboard button is pressed then you start asking how it's possible to simultaneously press the mouse and keyboard in FPS games. So i'm a bit confused.
WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 25th Mar 2009 01:36
I gotten it to work. I just need dbEscapeKey() and dbMouseClick() in if statements. The statements need to be in an infinite loop. I need a timer. I also need dbSync() to ensure that the program does not appear as though it is frozen.

This is the third time I had posted a problem and also the third time in a row that I had to solve the problem that I posted myself.
action 9000
16
Years of Service
User Offline
Joined: 27th May 2008
Location: Alberta, Canada
Posted: 25th Mar 2009 01:39 Edited at: 25th Mar 2009 01:41
We can't do it that way but I think we can cheat:



Is this okay?

If you want, you can store
dbScanCode() and dbMouseClick()
to variables so you can control them better.
WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 25th Mar 2009 01:43
I don't know how to explain it. Read my response above. try it yourself. Maybe then it will be clear of what I want to do.
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 25th Mar 2009 02:16
@action 9000

I would add dbWait(500) inside of the loop or else the program will run as fast as it can inside of the while loop, using a lot of cpu time.

#ifdef _DEBUG
FixBugs(All);
#endif
WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 25th Mar 2009 02:23
I think that might work Action 9000. Thank you. The problem I can see existing in the code that you given me is that I would have to press the escape key twice if I want to pause the program with your method so that I can press the escape key later. I actually found a different way to get what I want to happen to happen. I just need dbMouseClick()'s and dbEscapceKey()'s in a while ( true ). To make things work out the way I want exactly, I need to use dbSync() at the beginning of the inside of the while ( true )and a Hold variable. The hold variable prevents the user from holding onto the left mouse click button in order to fire the if ( dbMouseClick() == 1 ... ) statements. The user has to make a left-click everytime to fire the statements. This is the method that I am using right now.
action 9000
16
Years of Service
User Offline
Joined: 27th May 2008
Location: Alberta, Canada
Posted: 25th Mar 2009 02:28 Edited at: 25th Mar 2009 02:28
@ Bran flakes

Wouldn't that only be necessary if you were concerned about multithreading the program?

For program responsiveness' sake, I'd probably use a smaller number like dbWait(50) or (100).

You're right though, dbWait() would save some wear and tear on the CPU at the very least.
WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 25th Mar 2009 02:33
What is strange is that by using dbSync() at the beginning of the inside of the while ( true ), my computer fan does not spin quickly and loudly as it would if the dbSync() was not there. Why would the fan noise have anything to do with an infinite loop you ask? The fan speed and noise tell me how hard the CPU is working. This is so because I believe that the fan that is making the noise is the CPU fan and is affected by the activities of the CPU. By not hearing the noise when the dbSync() exists in my program, it makes me think that something strange is going on and that either the looping is slower or not happening at all... When dbSync() is not in my program, I do hear the fan noise and the program "acts" as though it is frozen.
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 25th Mar 2009 16:33

Login to post a reply

Server time is: 2024-09-30 21:25:25
Your offset time is: 2024-09-30 21:25:25