Generating events
As you know, Game Maker is completely event driven. All actions happen as the result of events. There are a number of different events. Creation and destroy events happen when an instance is created or destroyed. In each step, the system first handles the alarm events. Next it handles keyboard and mouse events and next the step event. After this the instances are set to their new positions after which the collision event is handled. Finally the draw event is used to draw the instances (note that when there are multiple views the draw event is called multiple times in each step). You can also apply an event to the current instance from within a piece of code. The following functions exist:
event_perform(type,numb) Performs event numb of the indicated type to the current instance.The following event types can be indicated:
- ev_create
- ev_destroy
- ev_step
- ev_alarm
- ev_keyboard
- ev_mouse
- ev_collision
- ev_other
- ev_draw
- ev_keypress
- ev_keyrelease
When there are multiple events of the given type, numb can be used to specify the precise event. For the alarm event numb can range from 0 to 11. For the keyboard event you have to use the keycode for the key. For mouse events you can use the following constants:
- ev_left_button
- ev_right_button
- ev_middle_button
- ev_no_button
- ev_left_press
- ev_right_press
- ev_middle_press
- ev_left_release
- ev_right_release
- ev_middle_release
- ev_mouse_enter
- ev_mouse_leave
- ev_mouse_wheel_up
- ev_mouse_wheel_down
- ev_global_left_button
- ev_global_right_button
- ev_global_middle_button
- ev_global_left_press
- ev_global_right_press
- ev_global_middle_press
- ev_global_left_release
- ev_global_right_release
- ev_global_middle_release
- ev_joystick1_left
- ev_joystick1_right
- ev_joystick1_up
- ev_joystick1_down
- ev_joystick1_button1
- ev_joystick1_button2
- ev_joystick1_button3
- ev_joystick1_button4
- ev_joystick1_button5
- ev_joystick1_button6
- ev_joystick1_button7
- ev_joystick1_button8
- ev_joystick2_left
- ev_joystick2_right
- ev_joystick2_up
- ev_joystick2_down
- ev_joystick2_button1
- ev_joystick2_button2
- ev_joystick2_button3
- ev_joystick2_button4
- ev_joystick2_button5
- ev_joystick2_button6
- ev_joystick2_button7
- ev_joystick2_button8
For the collision event you give the index of the other object. Finally, for the other event you can use the following constants:
- ev_outside
- ev_boundary
- ev_game_start
- ev_game_end
- ev_room_start
- ev_room_end
- ev_no_more_lives
- ev_no_more_health
- ev_animation_end
- ev_end_of_path
- ev_close_button
- ev_user0
- ev_user1
- ev_user2
- ev_user3
- ev_user4
- ev_user5
- ev_user6
- ev_user7
- ev_user8
- ev_user9
- ev_user10
- ev_user11
- ev_user12
- ev_user13
- ev_user14
- ev_user15
For the step event you give the index can use the following constants:
- ev_step_normal
- ev_step_begin
- ev_step_end
You can get information about the current event being executed using the following read-only variables:
event_type* Type of the current event begin executed. event_number* Number of the current event begin executed. event_object* The object index for which the current event is being executed. event_action* The index of the action that is currently being executed (0 is the first in the event, etc.).
Contributor: Mark Overmars

Related: