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

virtual_key_show (illegal virtual key handle error)

Hi to all.
to close my textbox on android device I want to set a virtual key managed by the dialog box object. code here:
GML:
avanza_chiudi = keyboard_check_pressed(vk_space);
ascissaBox = (camera_get_view_x(view_camera[0]));
ordinataBox = (camera_get_view_y(view_camera[0])+164);

if testo_dialogo == ""
{
   testo_dialogo = "proprietario "+string(proprietario);
}
//show_debug_message("proprietario "+string(proprietario.id));
if avanza_chiudi//keyboard_check_pressed(vk_backspace)//aalora a funzionare funziona, il problema è che non ho una keyboard sul telefono
{
    if (pag+1 < array_length_1d(testo_dialogo))
        pag +=1;    //quindi farò con l'event del tap da cellulare
    else
        instance_destroy();
}
    
avanza_chiudi = virtual_key_add(ascissaBox+448, ordinataBox, 32, 32, vk_space);

virtual_key_show(avanza_chiudi);

the button should work but it doesn't. and to understand where it appeared I entered the show_virtual_key but it gives me an error : "illegal virtual key handle at line etc....etc..."
the dialog box is created in a different layer from that of the Instances
any suggestions?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You are creating a new virtual key every step and this is probably the issue. You only need to create them once per room, so move the add function in to the Create Event.
 
would you believe it?
if I move the command assignment to create event, it automatically sends them to me as if they had been executed and the dialog box opens and closes at the speed of light,
or they simply don't work
 
I wrote this double effect because even on the initial screen I have the same problem with the button to start the game. keyboard input works and its virtual_key does not.
or better. now place two codes. they are apparently identical
GML:
iniziagioco = keyboard_check_pressed(ord("T"));

if iniziagioco
    room_goto_next();

iniziagioco = virtual_key_add(room_width/2-120, room_height/2, 240, 48, iniziagioco);
Code:
iniziagioco = keyboard_check_pressed(ord("T"));



iniziagioco = virtual_key_add(room_width/2-120, room_height/2, 240, 48, iniziagioco);


//virtual_key_show(iniziagioco);

if iniziagioco
    room_goto_next();
are both Step event of start screen. in the first the virtual key don't run but if i press T i start the game.
in the code below as game maker compile the game starts, as i've pressed T or virtual key on screen
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
GML:
iniziagioco = virtual_key_add(room_width/2-120, room_height/2, 240, 48, ord("T");
This is all wrong I'm afraid. Let me outline what you need to do...

GML:
// CREATE EVENT
// DEFINE THE VIRTUAL KEY AND STORE THE KEY ID IN A VARIABLE
my_vk = virtual_key_add(room_width/2-120, room_height/2, 240, 48, ord("T"));  // You may need to edit the position as virtual keys are defined in GUI space, not room space
virtual_key_show(my_vk);

// STEP EVENT
// CHECK FOR THE KEY THAT THE VIRTUAL KEY REPRESENTS
if keyboard_check_pressed(ord("T"))
{
room_goto_next();
}

// DESTROY EVENT
// DESTROY THE VIRTUAL KEY USING THE STORED KEY ID WHEN NOT IN USE
virtual_key_delete(my_vk);
You need to learn to use the manual to see what each of the functions does and how they should be used as you aren't using any of them correctly currently I'm afraid.... Hopefully the code I've shown here will help you get on though!
 
thnks, i've found a tutorial online on which I noticed that the key sequence was not stored in a variable before being inserted into the virtual keys. so i've wrote this
GML:
/// @description Insert description here
// You can write your code in this editor
//iniziagioco = keyboard_check_pressed(ord("T"));

    if keyboard_check_pressed(ord("T"))
        room_goto_next();

//iniziagioco = virtual_key_add(room_width/2-120, room_height/2, 240, 48, iniziagioco);


//virtual_key_show(iniziagioco);
and in create event add
Code:
/// @description Insert description here
// You can write your code in this editorwith o_PlayerMobile
iniziagioco = virtual_key_add(room_width/2-120, room_height/2, 240, 48, ord("T"));
in this way it run!!


but it also doesn't work in the dialog box object
Code:
create
/// @description Insert description here
// You can write your code in this editor
proprietario = -1;
testo_dialogo = -1;
pag = 0;

ascissaBox = 0;
ordinataBox = 0;

larghezzaBox = sprite_get_width(s_box_dialogo);
altezzaBox = sprite_get_height(s_box_dialogo);
altezzaTesto = string_height(testo_dialogo);

avanzachiudi = virtual_key_add(ascissaBox+448, ordinataBox, 32, 32, ord("U"));

step
/// @description Insert description here
// You can write your code in this editor

ascissaBox = (camera_get_view_x(view_camera[0]));
ordinataBox = (camera_get_view_y(view_camera[0])+164);


//show_debug_message("proprietario "+string(proprietario.id));
if keyboard_check_pressed(ord("U"))//aalora a funzionare funziona, il problema è che non ho una keyboard sul telefono
{
    if (pag+1 < array_length_1d(testo_dialogo))
    {
        if testo_dialogo != ""
            pag +=1;    //quindi farò con l'event del tap da cellulare
            else
        instance_destroy();
    } 
    else
        instance_destroy();
}

if testo_dialogo == ""
{
   testo_dialogo = "proprietario "+string(proprietario);
}
  
//avanza_chiudi = virtual_key_add(ascissaBox+448, ordinataBox, 32, 32, vk_space);

//virtual_key_show(avanzachiudi);
why? the dialog_box is visible but has no sprite
 
Last edited:
Top