• 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!

Mac OSX Getting mouse or keyboard state at game launch (Mac only maybe?)

bsabiston

Member
I doubt anyone will have an answer for this, but ...

I'm trying to detect the SHIFT key being held down at the time I launch my game - I want it to start up in a different configuration in that case.

var shiftKey = keyboard_check(vk_shift)

But, on MacOS at least, the keyboard_check commands don't work at that time.
Maybe because the window has not been created yet or received focus? I'm not sure. Although the window is there on screen and looks to have focus when I do my check.
The keyboard and mouse commands work at other times, so it seems to have something to do with the game first starting?

I also tried keyboard_check_direct and that returned "undefined"

I also tried testing the mouse instead:

var mouseDown = mouse_check_button_pressed(mb_left)

but that also does not correctly detect the mouse held down.
Anyone know how to do it or some other alternative?
 
Last edited:
I don't think you being on mac has anything to do with your issue, though I'm just going off of the top of my head here :)

As far as I l know GMS only does anything prior to a room starting if you use creation code.

Isn't the title screen of your game a room? You want an object there, and should put the keyboard code in it's creation code.

This code is run before the room starts, and I'm assuming it can change the set-up before the player even see's anything.

EDIT:
Regarding keyboard_check_direct.............

keyboard_check_direct
NOTE: This function is only available for the standard Windows target
 

bsabiston

Member
Thanks - but the point is not just to configure things before the game starts. I can already do that. I want to do it dynamically, like do something different depending on what key or button I have held down.
So I am already doing my checks in the same place I do the configuration. The problem is that those keyboard and mouse checks are not working.
 

bsabiston

Member
The configuration is what determines what window size to use, along with a bunch of other things that determine whether it is running on desktop or phone. I can't switch that to later, unfortunately.
Basically I want to be able to make it start up in phone mode on the desktop if I am holding down a key...
 
The Other Event Game Start
This special event is triggered only once in the whole game and only for those instances with actions or code placed in the event. These instances must be present in the first room of the game and have been placed there in the room editor, rather than have been created dynamically. It should be noted that this event happens after the create event of all instances and so can contain code or actions with variables that have been previously defined in that event. This event is typically defined in only one "controller" object and is typically used to initialize global variables, start music, read from files and any other thing that is usually only done once at the start of a game.


This would seem to be an event that could be guaranteed to run, and I'm assuming GMS would require knowing it is in "focus"? though I'm not a mac user. So I have no clue if the OS is your problem, or if it's what you're trying to do in GMS, and when you're doing it....
 
Top