• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED] Key pressed if window is not in focus (not active)

P

puppo

Guest
Hi, this is my first post on the forum. I'm moving my first steps in the GameMaker world, and through Drag and Drop I created a simple counter with three keypad keys: "+" to add, "-" to subtract, "0" to reset. Everything works well, but I would like it to work even when the counter window is not active, or in other words is not in focus.

In the manual I saw the function "keyboard_check_direct". I tried to use it in the Step event:

Code:
if keyboard_check_direct(vk_add)
   {
   counter += 1;
   }
if keyboard_check_direct(vk_subtract)
   {
   counter -= 1;
   }
But of course when I press the + or - keys, the numbers grow or decrease too fast.
What I would need is a function like "keyboard_check_direct_pressed", but I think it does not exist.

Is there a way to solve this problem?
My GameMaker version is 8.1.

Thanks!
 
I don't know if that would work in GM8 but if you want to increase only 1, then you should use keyboard_check_pressed()

Also if you are really new to GameMaker, you should start from GM:S 1.4 in my opinion :)

I don't know if you can access the game when the tab is inactive :(
 

Tsa05

Member
It seems that you're off to an odd start. Your first game in GameMaker requires inputs when the game is *not* active? What are you trying to do, more exactly? I feel like there's info missing here.
 
P

puppo

Guest
Add in a custom variable.
Code:
if (keyboard_check_direct(vk_add))
{
    if (can_add)
    {
        can_add  = 0;
        counter += 1;
    }
}
else
    can_add = 1;
Thank you very much BattleRifle BR55, that's exactly what I was looking for! I added the "can_add" and "can_subtract" variables in the Create event and I put your code in the Step event. And now when the window is not in focus everything works fine! Thanks again!!! :):):)

I don't know if that would work in GM8 but if you want to increase only 1, then you should use keyboard_check_pressed()

Also if you are really new to GameMaker, you should start from GM:S 1.4 in my opinion :)

I don't know if you can access the game when the tab is inactive :(
Unfortunately, if the window is inactive the "keyboard_check_pressed()" function does not receive keyboard commands... :(

It seems that you're off to an odd start. Your first game in GameMaker requires inputs when the game is *not* active? What are you trying to do, more exactly? I feel like there's info missing here.
As I said at the beginning, I'm creating a simple counter that also works when its window is not active. In fact it's not a game, but a small utility. ;)
 
Top