Skip to content

Commit

Permalink
sticky virtual keyboard keys implemented.
Browse files Browse the repository at this point in the history
The alt, ctrl, amiga, and shift virtual keyboard keys are now sticky. Press them once to enable and another time to let go of the key. Key combos like "Amiga-Q" can now be entered using the virtual keyboard. The circle button quickly un-sticks all keys.
  • Loading branch information
rsn8887 committed Jan 6, 2018
1 parent 70d8f55 commit 5351eef
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 124 deletions.
16 changes: 13 additions & 3 deletions Readme.txt
Expand Up @@ -49,6 +49,7 @@ VITA-EXCLUSIVE FEATURES:
- Additional emulator settings: sprite-sprite collisions can be enabled, blitter settings can be changed
- Adjustable stereo separation
- Bluetooth keyboard and mouse support
- Sticky virtual keyboard modifiers: allows keyboard combos like CTRL-C to be entered easily

NOTES:

Expand Down Expand Up @@ -92,8 +93,11 @@ Dpad = Amiga joystick directions

When custom controls are off:
L/R shoulder buttons = Mousebuttons
Square = Joystick button autofire (can be customized)
X = Joystick button (can be customized)
(Shown below are control presets 1 (default) / 2 / 3 / 4)
Square = Autofire (default) / Fire / Autofire / Fire
Cross = Fire (default) / Autofire / Up (Jump) / Up (Jump)
Triangle = Space (default) / Space / Fire / Autofire
Circle = Secondary Fire (used only in a few games)
R+Square = Ctrl
R+Circle = Left Alt
R+Cross = Help
Expand All @@ -108,10 +112,16 @@ Virtual keyboard controls:
Start = Toggle virtual keyboard
Right analog stick up/down = Move virtual keyboard up and down
Right analog stick left/right = Change virtual keyboard transparency
Cross = Press selected key
Square = Backspace
Triangle = Toggle Shift
Triangle = Toggle shift
Circle = Turn off all sticky keys (ctrl, alt, amiga, and shift)

CHANGELOG:
1.57

- Sticky virtual keyboard keys implemented. The alt, ctrl, amiga, and shift virtual keyboard keys are now sticky. Press them once to enable and another time to let go of the key. Key combos like "Amiga-Q" can now be entered using the virtual keyboard. The circle button quickly un-sticks all keys.

1.56

- fix keys being pressed when pressing Vita buttons (introduced in 1.55)
Expand Down
67 changes: 41 additions & 26 deletions src/gui.cpp
Expand Up @@ -160,10 +160,10 @@ int dpadUp[4]={0,0,0,0};
int dpadDown[4]={0,0,0,0};
int dpadLeft[4]={0,0,0,0};
int dpadRight[4]={0,0,0,0};
int buttonA[4]={0,0,0,0};
int buttonB[4]={0,0,0,0};
int buttonX[4]={0,0,0,0};
int buttonY[4]={0,0,0,0};
int buttonA[4]={0,0,0,0}; // Vita Square, GP2X_BUTTON_B
int buttonB[4]={0,0,0,0}; // Vita Circle, GP2X_BUTTON_A
int buttonX[4]={0,0,0,0}; // Vita Cross, GP2X_BUTTON_X
int buttonY[4]={0,0,0,0}; // Vita Triangle, GP2X_BUTTON_Y
int triggerL[4]={0,0,0,0};
int triggerR[4]={0,0,0,0};
int buttonSelect[4]={0,0,0,0};
Expand Down Expand Up @@ -432,7 +432,7 @@ static void goMenu(void)
}
if(gp2xButtonRemappingOn)
togglemouse();
uae_reset ();
uae_reset ();
}
check_all_prefs();
gui_purge_events();
Expand Down Expand Up @@ -1188,7 +1188,7 @@ if(!vkbd_mode)
{
for (int i=0; i<nr_joysticks; i++)
{
if(mainMenu_custom_dpad == 0)
if(mainMenu_custom_dpad == 0) // always true on Vita
{
//UP
if(dpadUp[i])
Expand Down Expand Up @@ -1930,44 +1930,59 @@ if(!vkbd_mode)
}

#ifdef USE_UAE4ALL_VKBD
if (vkbd_key!=-1234567) // This means key was selected by user. We cannot test for zero, because that is a valid Amiga keycode
if (vkbd_key!=KEYCODE_NOTHING) // This means key was selected by user. We cannot test for zero, because that is a valid Amiga keycode
{
if (vkbd_keysave==-1234567) // the previous vkbd key was released. Press the new key for one frame
if (vkbd_key >= 0)
{
vkbd_keysave=vkbd_key; // remember which key we are pressing so we can release it later
if (vkbd_keysave >= 0)
// Handle all sticky keys (release and press) here up front
bool sticky=false;
for (int i=0; i<NUM_STICKY; i++)
{
if (!uae4all_keystate[vkbd_keysave])
if (vkbd_key == vkbd_sticky_key[i].code)
{
if ((vkbd_shift) && uae4all_keystate[AK_LSH] == 0)
if ((vkbd_sticky_key[i].stuck) && uae4all_keystate[vkbd_sticky_key[i].code] == 0)
{
uae4all_keystate[AK_LSH]=1;
record_key(AK_LSH<<1);
uae4all_keystate[vkbd_sticky_key[i].code]=1;
record_key(vkbd_sticky_key[i].code<<1);
}
if (!(vkbd_shift) && uae4all_keystate[AK_LSH] == 1)
if (!(vkbd_sticky_key[i].stuck) && uae4all_keystate[vkbd_sticky_key[i].code] == 1)
{
uae4all_keystate[AK_LSH]=0;
record_key((AK_LSH<<1)|1);
uae4all_keystate[vkbd_sticky_key[i].code]=0;
record_key((vkbd_sticky_key[i].code<<1)|1);
}
sticky=true; // a sticky key was pressed and handled. We are done.
break;
}
}
if (!sticky && vkbd_keysave==KEYCODE_NOTHING) // a non-sticky key was pressed and previous key was released. Press the new key
{
vkbd_keysave=vkbd_key; // remember which key we are pressing so we can release it later
if (!uae4all_keystate[vkbd_keysave])
{
uae4all_keystate[vkbd_keysave]=1;
record_key(vkbd_keysave<<1);
record_key(vkbd_keysave<<1);
}
}
} else if (vkbd_key == KEYCODE_STICKY_RESET) // the special button to reset all sticky keys was pressed
{
for (int i=0; i<NUM_STICKY; i++)
{
if (uae4all_keystate[vkbd_sticky_key[i].code] == 1)
{
uae4all_keystate[vkbd_sticky_key[i].code]=0;
record_key((vkbd_sticky_key[i].code<<1)|1);
}
}
}
}
else if (vkbd_keysave!=-1234567)
else if (vkbd_keysave!=KEYCODE_NOTHING) // some non-sticky key was released
{
if (vkbd_keysave >= 0) //turn off shift together with any other key release if it was on
if (vkbd_keysave >= 0) //handle key release
{
if (uae4all_keystate[AK_LSH] == 1)
{
uae4all_keystate[AK_LSH]=0;
record_key((AK_LSH<<1)|1);
}
uae4all_keystate[vkbd_keysave]=0;
record_key((vkbd_keysave << 1) | 1);
}
vkbd_keysave=-1234567;
vkbd_keysave=KEYCODE_NOTHING;
}
#endif
}
Expand Down
7 changes: 7 additions & 0 deletions src/main.cpp
Expand Up @@ -57,6 +57,10 @@ extern SDL_Surface *current_screenshot;
#include "gp2xutil.h"
#endif

#ifdef USE_UAE4ALL_VKBD
#include "vkbd.h"
#endif

#ifdef __PSP2__
//Allow locking PS Button
#include <psp2/shellutil.h>
Expand Down Expand Up @@ -153,6 +157,9 @@ int quit_program = 0;
void uae_reset (void)
{
gui_purge_events();
#ifdef USE_UAE4ALL_VKBD
vkbd_reset_sticky_keys(); // keyvalues clear on reset, so vkbd must reflect this
#endif
black_screen_now();
quit_program = 2;
set_special (SPCFLAG_BRK);
Expand Down
14 changes: 11 additions & 3 deletions src/od-joy.cpp
Expand Up @@ -551,6 +551,12 @@ void read_joystick(int nr, unsigned int *dir, int *button)
buttonA[0] = 0;
*button = 0;
}
else if (buttonB[0])
{
vkbd_move=VKBD_BUTTON_RESET_STICKY;
buttonB[0] = 0;
*button = 0;
}
#else // in other cases where those buttons might not be available, use the amiga joystick
if (*button || buttonX[0] )
{
Expand All @@ -559,9 +565,11 @@ void read_joystick(int nr, unsigned int *dir, int *button)
*button = 0;
}
#endif
else //button release, make shift toggle possible again.
{
vkbd_can_switch_shift=1;
else { //button release, pressing sticky keys is possible again.
for (int i=0; i<NUM_STICKY; i++)
{
vkbd_sticky_key[i].can_switch=true;
}
}
// TODO: add vkbd_button2 mapped to button2
}
Expand Down

0 comments on commit 5351eef

Please sign in to comment.