Controller

Data Structures

union  OSL_KEYLIST
 
struct  OSL_CONTROLLER
 
union  OSL_REMOTEKEYLIST
 
struct  OSL_REMOTECONTROLLER
 

Macros

#define oslSetKeyAutorepeat(keys, init, interval)   ( osl_keys->autoRepeatMask = keys, osl_keys->autoRepeatInit = init, osl_keys->autoRepeatInterval = interval )
 
#define oslSetKeyAutorepeatMask(mask)   (osl_keys->autoRepeatMask=mask)
 
#define oslSetKeyAutorepeatInit(value)   (osl_keys->autoRepeatInit=value)
 
#define oslSetKeyAutorepeatInterval(value)   (osl_keys->autoRepeatInterval=value)
 
#define oslSetKeyAnalogToDPad(sensivity)   (osl_keys->analogToDPadSensivity = sensivity)
 
#define oslSetRemoteKeyAutorepeat(keys, init, interval)   ( osl_remotekeys->autoRepeatMask = keys, osl_remotekeys->autoRepeatInit = init, osl_remotekeys->autoRepeatInterval = interval )
 
#define oslSetRemoteKeyAutorepeatMask(mask)   (osl_remotekeys->autoRepeatMask=mask)
 
#define oslSetRemoteKeyAutorepeatInit(value)   (osl_remotekeys->autoRepeatInit=value)
 
#define oslSetRemoteKeyAutorepeatInterval(value)   (osl_remotekeys->autoRepeatInterval=value)
 

Enumerations

enum  OSL_KEY_BITS {
  OSL_KEY_SELECT =1, OSL_KEY_START =4, OSL_KEY_UP =5, OSL_KEY_RIGHT =6,
  OSL_KEY_DOWN =7, OSL_KEY_LEFT =8, OSL_KEY_L =9, OSL_KEY_R =10,
  OSL_KEY_TRIANGLE =13, OSL_KEY_CIRCLE =14, OSL_KEY_CROSS =15, OSL_KEY_SQUARE =16,
  OSL_KEY_HOME =17, OSL_KEY_HOLD =18, OSL_KEY_NOTE =24
}
 
enum  OSL_KEY_MASKS
 

Functions

OSL_CONTROLLERoslReadKeys ()
 
int oslSetReadKeysFunction (int(*sceCtrlReadBufferPositive)(SceCtrlData *pad_data, int count))
 
int oslUnsetReadKeysFunction ()
 
int oslSetHoldForAnalog (int holdForAnalog)
 
int oslWaitKey ()
 
int oslKbhit ()
 
void oslFlushKey ()
 
OSL_REMOTECONTROLLERoslReadRemoteKeys ()
 
void oslFlushRemoteKey ()
 
int oslIsRemoteExist ()
 

Variables

OSL_CONTROLLERosl_keys
 
OSL_CONTROLLER osl_pad
 
OSL_REMOTECONTROLLER osl_remote
 

Detailed Description

Controller functions in OSLib.

Macro Definition Documentation

#define oslSetKeyAutorepeat (   keys,
  init,
  interval 
)    ( osl_keys->autoRepeatMask = keys, osl_keys->autoRepeatInit = init, osl_keys->autoRepeatInterval = interval )

Sets the auto-repeat parameters (all at once).

Parameters
keysSets the keys affected by the autorepeat feature. If these keys are held for long enough, they will be reported more times in the pressed member in the osl_pad structure. It's the ideal thing to handle a menu, just check for the 'pressed' member and move the cursor when it's set. The auto-repeat feature will automatically work. Typical keys the user would expect to be auto-repeated are: OSL_KEYMASK_UP|OSL_KEYMASK_RIGHT|OSL_KEYMASK_DOWN|OSL_KEYMASK_LEFT|OSL_KEYMASK_R|OSL_KEYMASK_L. As you see, just OR the masks of the keys you want to be auto-repeated.
initTime (in number of calls, so at 60 fps, 60 = 1 second) before the auto-repeat feature turns on. Usually you must wait a while (1/2 second or more) before the auto-repeat is turned on, but once it's on, the key will be repeated more than each 1/2 second. A typical value here is 40 (2/3 second).
intervalTime interval between each key repeat when the auto-repeat has been turned on. A typical value is 10 (1/6 of a second); with the example above, you would press the key, then 2/3 second later it begins to auto-repeat the key each 1/6 second.
#define oslSetKeyAutorepeatMask (   mask)    (osl_keys->autoRepeatMask=mask)

Separate routine setting the key auto-repeat mask.

#define oslSetKeyAutorepeatInit (   value)    (osl_keys->autoRepeatInit=value)

Separate routine setting the key auto-repeat initialization value.

#define oslSetKeyAutorepeatInterval (   value)    (osl_keys->autoRepeatInterval=value)

Separate routine setting the key auto-repeat interval value.

#define oslSetKeyAnalogToDPad (   sensivity)    (osl_keys->analogToDPadSensivity = sensivity)

Enables or disable automatic redirection from the analog stick to D-Pad buttons (down, left, etc.).

Parameters
sensivitySensivity for the analog press. Analog values go from -128 to 127, so the maximum sensivity value you can set is 127, meaning the stick needs to be at least at -127 or +127 in each direction to be treated as a directional key.

A typical value is 80, this leaves a sufficient space to avoid unintentioned diagonals, but is also small enough to be sensitive and comfortable.

Note: Diagonal keys are supported as well with the stick, and this is really a good idea to at least enable this if you don't want to threat the stick separately. Some people (including me) have a weak D-Pad and it's extremely hard to play any game or app that needs the up/down keys, or even worse: diagonals.

//Enable default analog handler
//Read keys
//The stick is upwards OR the D-pad's up direction is held
{}
//If you want to differenciate stick and D-pad, you can also do something like this:
//Make sure default analog handler is disabled!
//D-Pad
{}
//Stick
if (osl_pad.analogY < -80)
{}
#define oslSetRemoteKeyAutorepeat (   keys,
  init,
  interval 
)    ( osl_remotekeys->autoRepeatMask = keys, osl_remotekeys->autoRepeatInit = init, osl_remotekeys->autoRepeatInterval = interval )

Sets the auto-repeat parameters (all at once).

Parameters
keysSets the keys affected by the autorepeat feature. If these keys are held for long enough, they will be reported more times in the pressed member in the osl_pad structure. It's the ideal thing to handle a menu, just check for the 'pressed' member and move the cursor when it's set. The auto-repeat feature will automatically work. Typical keys the user would expect to be auto-repeated are: OSL_KEYMASK_UP|OSL_KEYMASK_RIGHT|OSL_KEYMASK_DOWN|OSL_KEYMASK_LEFT|OSL_KEYMASK_R|OSL_KEYMASK_L. As you see, just OR the masks of the keys you want to be auto-repeated.
initTime (in number of calls, so at 60 fps, 60 = 1 second) before the auto-repeat feature turns on. Usually you must wait a while (1/2 second or more) before the auto-repeat is turned on, but once it's on, the key will be repeated more than each 1/2 second. A typical value here is 40 (2/3 second).
intervalTime interval between each key repeat when the auto-repeat has been turned on. A typical value is 10 (1/6 of a second); with the example above, you would press the key, then 2/3 second later it begins to auto-repeat the key each 1/6 second.
#define oslSetRemoteKeyAutorepeatMask (   mask)    (osl_remotekeys->autoRepeatMask=mask)

Separate routine setting the key auto-repeat mask.

#define oslSetRemoteKeyAutorepeatInit (   value)    (osl_remotekeys->autoRepeatInit=value)

Separate routine setting the key auto-repeat initialization value.

#define oslSetRemoteKeyAutorepeatInterval (   value)    (osl_remotekeys->autoRepeatInterval=value)

Separate routine setting the key auto-repeat interval value.

Enumeration Type Documentation

Bit number for each key in the 'value' field. One of these values is returned by oslKbhit or oslWaitKey.

keyPressed = oslWaitKey();
if (keyPressed == OSL_KEY_START)
...
Enumerator
OSL_KEY_SELECT 

Select key.

OSL_KEY_START 

Start key.

OSL_KEY_UP 

Up d-pad key.

OSL_KEY_RIGHT 

Right d-pad key.

OSL_KEY_DOWN 

Down d-pad key.

OSL_KEY_LEFT 

Left d-pad key.

OSL_KEY_L 

L (shoulder) key.

OSL_KEY_R 

R (shoulder) key.

OSL_KEY_TRIANGLE 

Triangle key.

OSL_KEY_CIRCLE 

Circle key.

OSL_KEY_CROSS 

Cross key.

OSL_KEY_SQUARE 

Square key.

OSL_KEY_HOME 

Home key (does not work in normal (user) operation)

OSL_KEY_HOLD 

Hold (power switch in the opposite direction) key.

OSL_KEY_NOTE 

Note key (same remark as Home)

Mask for each key in the 'value' field. To extract for example the select key, you can do the following:

if (osl_pad.held.value & OSL_KEYMASK_SELECT) ...
//This is equivalent to:

The keymasks description is exactly the same as keybits, they are just named OSL_KEYMASK_xxx instead of OSL_KEY_xxx.

Function Documentation

OSL_CONTROLLER* oslReadKeys ( )

Reads the current controller state and stores the result in the osl_pad structure. Returns a pointer to the actual key structure. It may seem cleaner to store this pointer and access data from it, but you can do however you want.

int oslSetReadKeysFunction ( int(*)(SceCtrlData *pad_data, int count)  sceCtrlReadBufferPositive)

Sets an external function to read keys. You can pass to it a function from a kernel prx, so you'll be able to read all buttons (VOLUME_UP, VOLUME_DOWN, NOTE...)

int oslUnsetReadKeysFunction ( )

Unsets the function set with oslSetReadKeysFunction

int oslSetHoldForAnalog ( int  holdForAnalog)

Decide if HOLD will affect also the analog (default=NO).

int oslWaitKey ( )

Waits for a key and returns its code. Compare the code against one of the OSL_KEYBITS values.

int oslKbhit ( )

Determines whether a key is currently buffered and returns its code, or 0 else. Compare the code against one of the OSL_KEYBITS values.

void oslFlushKey ( )

Flushes the key buffer, removing the pending key (retrievable with oslKbhit).

OSL_REMOTECONTROLLER* oslReadRemoteKeys ( )

Reads the current remote controller state and stores the result in the osl_remote structure. Returns a pointer to the actual key structure. It may seem cleaner to store this pointer and access data from it, but you can do however you want.

void oslFlushRemoteKey ( )

Flushes the remote key buffer, removing the pending key.

int oslIsRemoteExist ( )

Determines whether the remote is plugged in.

Returns
1 if the remote is plugged in, else 0.

Variable Documentation

OSL_CONTROLLER* osl_keys

Current keys. Only here for compatibility, use osl_pad now.

OSL_CONTROLLER osl_pad

Current keys. In this structure you will find three members: pressed, released and held.

  • pressed: keys that were just pressed, reported once when the user pressed it but not after.
  • held: always reported while the user holds the key.
  • released: reported when the user just releases a pressed key.

Each of these members is an union, containing a structure of type OSL_KEYLIST (contains a member for each key):

oslDebug("A pause should be thrown!");
oslDebug("Moving the main character upwards!");

Look at OSL_CONTROLLER for more information.

Current remote keys. In this structure you will find three members: pressed, released and held.

  • pressed: keys that were just pressed, reported once when the user pressed it but not after.
  • held: always reported while the user holds the key.
  • released: reported when the user just releases a pressed key.

Each of these members is an union, containing a structure of type OSL_REMOTEKEYLIST (contains a member for each key):

oslDebug("A pause should be thrown!");
oslDebug("Do something!");

Look at OSL_REMOTECONTROLLER for more information.