Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a log of a players actions as they play a game of Spelunky. The easiest I've found to do this is to log what keys are pressed at each frame. What I don't know how to do is how to integrate this with the Game Maker source code of Spelunky.

Is there a specific way to create a script that is checked every frame/tick (don't know the right term) and a command to find what buttons are pressed?

share|improve this question
up vote 6 down vote accepted

I would store the keys and times as two ds_lists.

Create an object and call it keyLogger (or whatever). In the create event, create two lists:

keyCodes = ds_list_create();
keyTimes = ds_list_create();
frame = 0;

Then, in the step event, you can log the keys and advance time.

    ds_list_add(keyCodes, keyboard_key);
    ds_list_add(keyTimes, frame);
frame += 1;

You can then draw all the keys in the draw event.

var i, s;
for(i = 0; i < ds_list_size(keyCodes); i += 1)
    s = "At frame ";
    s += string(ds_list_find_value(keyTimes, i));
    s += " you pressed key ";
    s += chr(ds_list_find_value(keyCodes, i));
    s += " (Code: ";
    s += string(ds_list_find_value(keyCodes, i));
    s += ")."
    draw_text(4, 4+i*20, s);

All you need to do is put this object in any room that you want to log keys in.

It should give an output that looks like this:

At frame 159 you pressed key F (Code: 14).

At frame 232 you pressed key 7 (Code: 95).

share|improve this answer
This is awesome thanks, the only issue I have is I also need to know how long a key was pressed, and if multiple keys are pressed at the same time. – skeletalmonkey Mar 21 '12 at 3:44

What might Be even simple but it could go bad, is if you logged the x and y of the character and stored then in a 2d array [frame,x or y Boolean value] then just repeat the sequence

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.