Can you map a joypad button to a keyboard key?

A forum about the Hatari ST/STE emulator - the current version is v2.0.0

Moderators: simonsunnyboy, thothy, Moderator Team

GrethTom
Atarian
Atarian
Posts: 6
Joined: Tue Mar 22, 2016 9:03 pm

Can you map a joypad button to a keyboard key?

Postby GrethTom » Sat Mar 26, 2016 5:15 pm

Hi all, in Hatari, can you map a joypad button to a keyboard key? I know spacebar is already hard coded and works well. Here would be my perfect setup on my 360 controller if its possible:

Select button = Esc
Start button = F12

Checked the manual and cannot find anything specific.

GrethTom
Atarian
Atarian
Posts: 6
Joined: Tue Mar 22, 2016 9:03 pm

Re: Can you map a joypad button to a keyboard key?

Postby GrethTom » Sun Apr 10, 2016 10:50 am

For anyone interested, after a bit of playing I got it working. I will go through the steps used on the RetroPie and hopefully it may be useful to someone. This link was a good starting point: http://blog.petrockblock.com/forums/top ... re-button/

First download source files for hatari:
cd RetroPie-Setup
sudo ./retropie_packages.sh hatari sources


then go to:
sudo nano /home/pi/RetroPie-Setup/tmp/build/hatari/src/joy.c


Within line 200 section:

Code: Select all

static bool Joy_ReadJoystick(int nSdlJoyID, JOYREADING *pJoyReading)


Add the following for F12 on Start button (on XBOX 360 controller):

Code: Select all

   if (SDL_JoystickGetButton(sdlJoystick[nSdlJoyID], 9))
   {
      Dialog_DoProperty();
   }


Add the following for Escape key on Select button (on XBOX 360 controller):

Code: Select all

   if (SDL_JoystickGetButton(sdlJoystick[nSdlJoyID], 8))
   {
      sdlevent.type = SDL_KEYDOWN;
      sdlevent.key.keysym.sym = SDLK_ESCAPE;
      sdlevent.key.keysym.mod = KMOD_NONE;

      SDL_PushEvent(&sdlevent);
      
      sdlevent.type = SDL_KEYUP;
      sdlevent.key.keysym.sym = SDLK_ESCAPE;
      sdlevent.key.keysym.mod = KMOD_NONE;

      SDL_PushEvent(&sdlevent);
   }


Once done, save the file then we have to build hatari:
sudo ./retropie_packages.sh hatari build


and finally
cd /home/pi/RetroPie-Setup/tmp/build/hatari
sudo make install


Make sure you reboot and should be good.

coverilla
Atarian
Atarian
Posts: 1
Joined: Thu Feb 02, 2017 8:51 am

Re: Can you map a joypad button to a keyboard key?

Postby coverilla » Thu Feb 02, 2017 8:59 am

Hi,

Thanks for your guide
During the build there were some errors:

Code: Select all

/home/pi/RetroPie-Setup/tmp/build/hatari/src/joy.c:218:3: error: ‘sdlevent’ undeclared (first use in this function)
   sdlevent.type = SDL_KEYDOWN;


at first sdlevent.type should be sdlEvent.type
secondly you are missing variable declaration:
Behind the:

Code: Select all

static bool Joy_ReadJoystick(int nSdlJoyID, JOYREADING *pJoyReading)
{

You should insert:

Code: Select all

        SDL_Event sdlEvent;

after these changes build was successful.


Social Media

     

Return to “Hatari”

Who is online

Users browsing this forum: No registered users and 1 guest