JPShortcut

JPShortcut

Associate your game actions with customizable shortcuts (keys, mouse/joypad buttons).
Version : 2.0
Price : $30
State : Out

Changelog

v2.0

  • Now compatible with ShiVa 2.0.
  • Plugin API compiled for Mac and Linux in addition to Windows : it will provide API completion in the Script module in ShiVa Editor for each of these operating systems.
  • Now uses a user token instead of an email to activate

v1.3

  • JPShortcut.setKeyName() now properly check its input parameter types

v1.2

  • Optimized for ShiVa 1.9.2

v1.1

You can now save the current shortcut configuration and load it at a later time. Here are the new functions:

  • bOK = JPShortcut.loadConfiguration ( sName )
  • bOK = JPShortcut.saveConfiguration ( sName )

It is now possible to set a custom name for a key or button, by using the following function:

  • JPShortcut.setKeyName ( kKeyCode, sName )

API

--JPShortcut API JPShortcut.activate ( sUserToken, sActivationKey ) --EVENTS "onActionShortcutPressed" ( sAction ) "onActionShortcutReleased" ( sAction ) "onActionShortcutAlreadyTaken" ( sAction, kKeyCode, sModifier, sActionToOverride ) "onActionShortcutUpdated" ( sAction, kKeyCode, sModifier ) --Creation/Update JPShortcut.createAction ( sAction, kKeyCode, sModifier ) bOK = JPShortcut.changeActionShortcut ( sAction, kKeyCode, sModifier, bOverride ) --Edition JPShortcut.startActionEdition ( sAction ) sAction = JPShortcut.getActionBeingEdited ( ) JPShortcut.cancelActionEdition ( ) sAction = JPShortcut.override ( ) --Remove JPShortcut.removeAction ( sAction ) JPShortcut.removeActionShortcut ( sAction ) JPShortcut.removeAllActions ( ) JPShortcut.resetAllActionsShortcut ( ) --Accessors kKeyCode, sModifier = JPShortcut.getActionDefaultShortcut ( sAction ) sAction = JPShortcut.getActionFromShortcut ( kKeyCode, sModifier ) kKeyCode, sModifier = JPShortcut.getActionShortcut ( sAction ) tActions, tKeyCodes, tModifiers = JPShortcut.getAllActions ( ) bYes = JPShortcut.isActionShortcutDown ( sAction ) --Keys and buttons JPShortcut.addDisabledJoypadButton ( nButton ) JPShortcut.addDisabledKeyboardButton ( kKeyCode ) JPShortcut.addDisabledMouseButton ( nButton ) JPShortcut.getJoypadButtonCode ( nButton ) JPShortcut.getMouseButtonCode ( nButton ) sName = JPShortcut.getKeyName ( kKeyCode ) JPShortcut.setKeyName ( kKeyCode, sName ) --Configurations bOK = JPShortcut.loadConfiguration ( sName ) bOK = JPShortcut.saveConfiguration ( sName ) --Misc JPShortcut.setModeExclusive ( bExclusive )

Description

In your game, when you want to do an action like moving a character, you will be listening to the keyboard events, to know if the key to move forward, backward or to start a specific action is pressed or released. That's great, but as soon as you allow the user to customize the actions key, it becomes much more complicated.

With JPShortcut, you will be listening for action events instead of keys. JPShortcut will send you events to let you know when an action shortcut is pressed or released, whatever the shortcut is.

JPShortcut embeds functions to be called by your shortcut editor interface. Tell JPShortcut that the "Forward" action has been clicked by the user to be edited, and JPShortcut will automatically change the shortcut as soon as a new key is pressed, and will notify you of the new key to let you update the interface with the new action key name.

JPShortcut is compatible with mouse buttons as well as joypad buttons.

Here is a quick example, starting from the setup step:

function JPShortcutSample.onInit ( ) JPShortcut.createAction ( "Forward", input.kKeyUp ) JPShortcut.createAction ( "Backward", input.kKeyDown ) JPShortcut.createAction ( "Left", input.kKeyLeft ) JPShortcut.createAction ( "Right", input.kKeyRight ) JPShortcut.createAction ( "Crouch", input.kKeySpace ) --Special action end

Here's the code if you want to do something as long as the action shortcut is pressed:

function JPShortcutSample.onEnterFrame ( ) if ( JPShortcut.isActionShortcutDown ( "Forward" ) ) then --Move forward end --Same for the other actions end

And here the code for actions called once, in the onActionShortcutPressed (or Released) handler, automatically called by JPShortcut when the action is triggered:

function JPShortcutSample.onActionShortcutPressed ( sAction ) if ( sAction == "Crouch" ) then --do the crouch action end end

In these 2 cases, even if the shortcut changes, your script remain the same as it is looking for actions state instead of keys or buttons states.