[solved] keyboard_key_press HTML5 issues

Discussion in 'Programming' started by THE_T_V1RUS, Jul 12, 2019 at 8:34 AM.

  1. THE_T_V1RUS

    THE_T_V1RUS Member

    Joined:
    Jun 8, 2018
    Posts:
    7
    UPDATE SOLVED:
    I just realized I have to use keyboard_key_release() after using keyboard_key_pressed(); Simple fix.



    I have the following code in the draw event for my object called obj_key_start:

    Code:
    if global.pause == true exit;
    
    for ( var i = 0; i < 10; i++)
        {
            if device_mouse_check_button_pressed(i,mb_left)
            {
                if device_mouse_x(i) > x
                if device_mouse_x(i) < x+sprite_width
                if device_mouse_y(i) > y
                if device_mouse_y(i) < y+sprite_height
                    {
                    show_debug_message("pessed");
                    keyboard_key_press(vk_enter);
                    }
            }
            if device_mouse_check_button(i,mb_left)
            {
                if device_mouse_x(i) > x
                if device_mouse_x(i) < x+sprite_width
                if device_mouse_y(i) > y
                if device_mouse_y(i) < y+sprite_height
                    {
                    draw_self();
                    }
            }
        }
    
    This all seems to work well. I click the start button object, I see my "pressed" message in the console, and an object in the room with a "Key Press - Enter" event gets triggered causing the game to proceed to the next room.

    However, when I try to click the start button again in this new room, I get strange behavior. I see my "pressed" message in the console every time I press it, but none of my objects with a "Key Press - Enter" event get triggered.

    There are two ways I can get clicking the start button to work again:
    1) I can manually press the enter key and then click the start button. And for some reason, manually pressing the enter key doesn't trigger any "Key Press - Enter" events. If I manually press the enter key a 2nd time, then the "Key Press - Enter" event triggers.
    2) I can click off the window or switch to a new tab, come back, and then click the start button object. Doing this causes the "Key Press - Enter" events to trigger.

    Any ideas on why this is happening? Is this a bug or am I doing something wrong?
     
    Last edited: Jul 12, 2019 at 8:56 AM

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice