Gamepad is recognized as a keyboard stroke?

S

Shy Lev-Ari

Guest
So I want my game to be able to detect a gamepad, and switch the graphic from keyboard hnts to gamepad hints, and vice versa.

I have this code:

Code:
for ( var i = gp_face1; i < gp_axisrv; i++ )
{
    if ( gamepad_button_check( 0, i ) )
    {
        global.keyboard = false;
    }
}

if    (keyboard_check(vk_anykey))
{
    global.keyboard = true;
}
When I test it, the first top works. global.keyboard is set to true by default, and after pressing a gamepad btn it is set to false.
When I add the second part (if... anykey) then the global.keyboard is always true. Does GMS detect the gamepad press as "vk_anykey"?

How else would you guys write this code?
 
S

Shy Lev-Ari

Guest
Can anybody help with this? It is driving me mad
I have also tried this:

Code:
if (global.keyboard)
{
    for ( var i = gp_face1; i < gp_axisrv; i++ )
    {
        if ( gamepad_button_check_pressed( 0, i ) )
        {
            global.keyboard = false;
        }
    }
}


if (!global.keyboard)
{
    if ( keyboard_check_pressed(vk_anykey))
    {
        global.keyboard = true;
    }
}
but it seems that when I use the left analog stick, it is recognized as a keyboard stroke :(
 

RangerX

Member
Ok its not really a solution for you maybe but I cut this problem really short in my game The Life Ruby.
When a gamepad is detected by the asynchronous event meant for it, I put a variable to true and when the gamepad is removed, I put it to false.
Thing is, if the player is having a gamepad plugged in its because he'll play your game with it. I stopped my thinking right there.
 
Try reversing the order:
Code:
if    (keyboard_check(vk_anykey))
{
   global.keyboard = true;
}
for ( var i = gp_face1; i < gp_axisrv; i++ )
{
   if ( gamepad_button_check( 0, i ) )
   {
       global.keyboard = false;
   }
}
If anykey is returning true when the gamepad is used, this should set it to false right after, meaning that if the user presses an actual key it will be set to true (as the gamepad code won't run), but if the user uses the gamepad, it'll be set to true then false. Kinda hacky but it should work.
 
S

Shy Lev-Ari

Guest
Ok its not really a solution for you maybe but I cut this problem really short in my game The Life Ruby.
When a gamepad is detected by the asynchronous event meant for it, I put a variable to true and when the gamepad is removed, I put it to false.
Thing is, if the player is having a gamepad plugged in its because he'll play your game with it. I stopped my thinking right there.
thanks for he suggestion. my game is small, kinda my first really. i will not publish i or anything, so this is just me trying to solve a puzzle :) a learning excersize, if you will
 
S

Shy Lev-Ari

Guest
You don't happen to have XPadder or anything like it accidentally running in the background, do you?
nope, not to my knoledge. it is an xbox360 gamepad. I did notice, however, that when the gamepad is turned on, the my cursor starts to drift towards the bottom left corner of the screen (if that matters).
 
S

Shy Lev-Ari

Guest
Try reversing the order:
Code:
if    (keyboard_check(vk_anykey))
{
   global.keyboard = true;
}
for ( var i = gp_face1; i < gp_axisrv; i++ )
{
   if ( gamepad_button_check( 0, i ) )
   {
       global.keyboard = false;
   }
}
If anykey is returning true when the gamepad is used, this should set it to false right after, meaning that if the user presses an actual key it will be set to true (as the gamepad code won't run), but if the user uses the gamepad, it'll be set to true then false. Kinda hacky but it should work.
Thanks for the attempt. The result is the same. I fire with the gamepad. The reload prompt I set up shows up. The proper asset shows up (the gamepad's A button). BUT if I use the left analog stick, the second asset (Keyboard's Ctrl key) will show up. Just to be clear, this is the code to show which asset:
Code:
if (!global.keyboard) draw_sprite_ext(spr_gamepad_a,0,room_width/2,room_height/2-(room_height*8/100),image_xscale,image_yscale,0,c_white,tempAlpha);
if (global.keyboard) draw_sprite_ext (spr_ctrl,0,room_width/2,room_height/2-(room_height*8/100),image_xscale,image_yscale,0,c_white,tempAlpha);
It's on the draw event, nothing fancy, very straightforward. And because of this I have to assume that some of the gamepad's keys are read as keyboard keys.
To stress this even further, my movement input has only been configured for keyboard vk_left / vk_right, and NOT for gamepad, and the gamepad sort of just "works". I want to say that THAT might be the problem, but the "Ctrl" asset also shows up when I tap left bumper, for example, and other random keys. Seems like only keys I defined (A,B and right trigger) DO NOT cause the system to think i is a keyboard (and right analog stick, for some reason. I have a feeling the right analog stick is simulating a mouse cursor and tht's why the system doesn't think it is a keyboard).

BTW, this is the game:
https://gamejolt.com/games/skyinvaders/332074

I can't publish it because I don't own any of the music :) (assets are all me though).
 

Gamebot

Member
nope, not to my knoledge. it is an xbox360 gamepad. I did notice, however, that when the gamepad is turned on, the my cursor starts to drift towards the bottom left corner of the screen (if that matters).
It moves the cursor most likely because you didnt set the deadzone correctly for the controller. Controllers are sensative and NOT perfectly straight. Therefore, your computer thinks your moving the right or left axis even though your not. I remember not setting it once...oops off the screen it went.

Try using: gamepad_set_deadzone in the create event.
 
S

Shy Lev-Ari

Guest
It moves the cursor most likely because you didnt set the deadzone correctly for the controller. Controllers are sensative and NOT perfectly straight. Therefore, your computer thinks your moving the right or left axis even though your not. I remember not setting it once...oops off the screen it went.

Try using: gamepad_set_deadzone in the create event.
yeah, no, regardless of Gamemaker. Turn on the gamepad - windows cursor hovers off
 
The windows cursor moves when it's plugged in? Make sure to check for any accessibility programs, too. By default, a plugged-in controller shouldn't have any effect.
 

Gamebot

Member
Oh that. Mine too. Happened after two updates ago. Stupid...

Thats why I dont plug them in until I am already running a seperate game or gm game. Seems to work that way.
 
Top