I'm making a text-based game. I'm trying to have a little "health bar". When the user hit space, and when the button is pressed it will make health go up by 5, but while this is also happening I need something to be running in the background that is doing the same as if it was a AI, except I want it to subtract 1 every time and for it to only hit it once every second.
I tried getch(); the most but the problem with that is that it stops everything and waits for the user to use a input so nothing can be going on in the background that is subtracting health.
If you could use the _getch(); command in any way to accomplish this, because I already know how to use it well.
Related
i want to detect User Idle Detection in c++
i used this winapi:
LASTINPUTINFO last_input;
last_input.cbSize = sizeof(LASTINPUTINFO);
last_input.dwTime = 0;
GetLastInputInfo(&last_input)
this methods work correctly with user Input like (mouse and keyboard),
but when i watch a movie this methods return wrong tickcount
i want right like "windows screen Saver" that detect user activity like (watch movie,mouse and keyboard) perfectly
how i can do this
thx
If you want to detect user idle, actually no user input, no display required, you can determines whether a screen saver is currently running using SPI_GETSCREENSAVERRUNNING.
If you want to get time period of user idle, you can see the last user input time as starting point and the time screen saver starts running as end point. Time difference between them is what you want.
More references: "System Sleep Criteria", "SystemParametersInfo()".
I have QToolButton:
btn_ = new QToolButton(this);
btn_->setFocusPolicy(Qt::NoFocus);
btn_->setAutoRepeat(false);
connect(btn_, SIGNAL(pressed()), this, SLOT(btnPressed()));
and my slot called twice per on appreciable press on touchpad.
During debug of my program I can see that the first one call from QAbstractButton::mousePressEvent
and the second one QAbstractButton::mouseMoveEvent.
If I press touchpad with one instantaneous and then remove hand from
touchpad, then I got only one call of btnPressed from QAbstractButton::mousePressEvent.
Any idea how to fix this issue? So I have not remove hands from notebook's touchpad
for pressing. I think about timer to measure time from one btnPressed to another,
but have no idea of value of timeout to prevent this. I can of course choose timeout for my notebook, but what if on another notebook it will be too small,
or if choose big one, then users start complains about not responsible interface.
linux/x11/qt4.8/amd64
Try using clicked() instead of pressed(), as it reflects the behaviour the user expect from a single button press/click. In general, if you're not sure you really want the slot called instantly at pressing the button (and handle the special cases that may come with that), you should use clicked().
Hi I have a question concerning error-messages.
I have a window with several buttons including a OK and Cancel-button. My OK-button executes a program that moves some chart series and for doing so it needs to read in lots of data from a file and shift these values. The Cancel button cancels this operation. The calculations cannot be separated into smaller portions of code.
This works well for smaller amount of data but when I use it with large sets of data the program acts as if it crashed. Nevertheless, after some time everything is back to normal, the calculation is done.
There are 2 things I don`t like:
1) When I leave the program alone the program changes the headerline of my window to ....(keine Rückmeldung) which means no response.
After the end of the calculation the text ...(keine Rückmeldung) disappears in the header and everything is back to normal.
2) When I try to press the "cancel" button in my window while running the calculation, an additional window appears:
There again, when I leave the program alone and the calculation is finished this window disappears ( as well as the (keine Rückmeldung) in the header of my window) and and everything is back to normal.
To solve problem 2 I tried to disable my "Cancel" button but this does not help. The slot which is behnid the cancel-button gets executed anyway.
My question now is: Since I don´t want the user to see these error-messages, is there a way to prevent the program of showing them?
Thank you
Consider using a QThread for expensive computation tasks. Or better, you can use other built-in multi-threading utilities such as QConcurrentRun and QFuture.
You can then easily get the state of your background function and show a loading Window, or allow the user to perform other operations in the meantime.
I'm having a hard time with GLFW's input system, figuring out how to make it work the way I want it, so I've come to people with more experience for wisdom. Using GLFW 3.
There are 3 states 0 Release, 1 Press and 2 Repeat. This is exactly what I would want, only, the key state from Press to Repeat takes about a second to change. Ideally, I would want it to have a state "Press" only for 1 frame, and then change into a repeat state.
The goal: Be able to easily call functions based on what state my key is as follows:
press Tap (do once)
repeat Continuous (do every frame)
release Don't respond
LINK
Please have a look in the files on the link above, and let me know if there's another way around it. Or is the approach itself rubbish, the way I do it? Thanks guys, all feedback and help appreiated.
One way is to simply ignore the "repeat" event, and only go with the "press" and "release" events.
When you get the "press" event set a flag, and clear the flag on the "release" event. Then simply check this flag every frame.
It is very important that there is a delay between "press" and "repeat". Most human beings are incapable of pressing and releasing a key, such that your game only registers the key being pressed for exactly one frame. And the few who are capable of that cannot do so consistently, with any accuracy.
So a user will never be able to "do once". They will be doing it for multiple frames. That's generally bad.
Also, there is a conceptual difference between pressing, holding, and repeating. Holding is just what happens when you hold down the key. Repeating is a facility that is governed by the OS (which is why GLFW doesn't give you a way to set the repeat rate). Key repeating is typically meant for text input (which GLFW takes care of for you anyway via its text-based callback).
Essentially, you should ignore it. In a game situation, a key has 4 possible useful states: not pressed, was just pressed, being held down, and was just released. You can infer this from the button's previous state (which you can store) and the button's current state provided by the callback.
If all you want to do is take an action when a button "was just pressed", then you need to know that the button was not pressed in the previous frame. If the key is pressed now but not in the previous frame, take the action.
I am trying to capture text from a Text Input box and fire off a function after the text is inputted. Only problem is the event is fired everytime a character is entered. I would like the event fired after all characters have been entered in the text input box. How could i delay the firing until all characters have been entered?
I tried to override the on_text method but did not solve my problem as it is this method that is being called 20 times. I also tried putting in a sleep in the on_text but it just buffered the responses and still fired 20 times.
Do exactly what you're already doing, but have the function you're calling check if whatever condition you're after is met. For instance, if you want to call it after 5 characters have been entered, check the length of the string.
This seems an awkward way of working though, are you sure you want to check after every character rather than, say, wait for the user to press enter?