TweetFollow Us on Twitter

Inside InputSprocket

Volume Number: 15 (1999)
Issue Number: 1
Column Tag: Games Programming

Inside InputSprocket

by Brent Schorsch

How to Use InputSprocket to Support User Input in Games

Introduction

Handing user input is a necessary aspect of a game. Without user input, it is not a game, but just a flashy movie. This article will cover what a game developer needs to do in order to handle user input using InputSprocket, Apple's gaming input API. InputSprocket was created to address the lack of a common API for joysticks and other gaming devices on the Macintosh platform. With the introduction of the iMac and USB, InputSprocket has opened the door for numerous gaming hardware manufactures to sell their products to Macintosh customers. Game developers also benefit by supporting InputSprocket because their game will support the latest input gadgets with no extra effort from the game developer. Game players benefit from the increased options.

The Basics

InputSprocket is a relatively simple API to use. There are some more complicated aspects, which will be covered later, but the basics are straightforward. First, an application must provide a list of its input needs to InputSprocket. Example needs a game might have are: fire weapon, jump, turn, look, rudder, lower landing gear. The list of needs determines how the user can interact with the game and therefore will directly affect whether the game is thought to be hard to control or very intuitive and flexible.

Once InputSprocket is initialized and has the list of needs, there is a single API call (ISpConfigure) which will bring up a user interface, provided by InputSprocket, for the user to map the physical elements of the device to needs in the game. InputSprocket maintains the user's settings in a preference file. This dialog is pictured in Figure 1.

During game play, the application can either get events or poll the current value for any of these needs. Typically, applications will get events on 'button kind' needs (and others) and poll the value of 'axis kind' needs once per game loop. The different 'kinds' of needs is covered later.


Figure 1. InputSprocket Configure Dialog.

The 'Low Level' Interface

In fact, there are two different ways an application can use InputSprocket: 'low-level' and 'high-level'. The 'low-level' interface provides a means for the developer to get a list of the devices currently available and manually check the state of each device. This interface is strongly discouraged. It is provided for those developers who wish to provide their own user interface to configuring device, but it puts a much greater burden on the game developer. With this interface, the game developer is responsible for determining how each kind of device might be configured to work with their game and to provide a complete user interface to make this configuration. Games that use the 'low-level' interface lose any extra functionality that is provided by the high level interface. The rest of this article will focus on the 'high-level' interface, which is the one that all game developers are encouraged to use.

Determining the Game's Needs

There are four basic need kinds: button, direction pad (dpad), axis and delta. (There is also a movement kind, but its use is discouraged.) Each kind has a different data format. The button kind is the simplest, with values of up or down. A dpad has nine possible values: idle, left, up-left, up, up-right, right, down-right, down, and down-left. An axis kind's value is a 32 bit unsigned number, regardless of whether it is symmetric. Finally, the value of a delta type is a 32 bit Fixed point number of inches moved.

When deciding what kind to make a particular need, one should prefer the axis kind to button and dpad kinds when applicable. This will allow game players to get the full functionality out of their equipment. Sure, keyboard users may only be able to either walk or run (forwards or backwards), but if someone has a device with enough 'analog' inputs, the game should let him continuously vary his speed. In some cases, it may be necessary to provide some extra information to InputSprocket so that the keyboard user experience is maintained which is covered later. Delta kinds are provide data similar to 'raw mouse' data but due to limitations in the current InputSprocket drivers, are most useful in the more complex InputSprocket cases, where once again extra information is provided.

In some cases, it may make sense to provide several needs that affect the same thing in the game world. For example, in addition to a 'next weapon' and 'previous weapon' need, it often makes sense to provide needs to switch to specific weapons, e.g. 'use machine gun', 'use plasma rifle'. The code necessary to support these different means to switch weapons is trivial, but the added functionality to certain users (with the right hardware) is immense. The speech recognition InputSprocket driver does not add much if you can only say 'next weapon', but if you can say 'use plasma rifle', then it might start to be appealing. Another case where multiple needs might make sense is where the need is some form of toggle, such as 'map mode' or 'landing gear'. One button may be sufficient for most users, but if the hardware physically has two states, like the caps lock key on some keyboards or any sort of lever, then it is very easy for the physical device to become out of sync with the game. However, by adding two more needs, switch to map view (or landing gear up) and switch to non-map view (or landing gear down), it is impossible, when properly configured, for the hardware to be out of sync with the game, regardless of the starting state of the game and the hardware.

Finally, it often makes sense to use the native data types as input for the game. This is a case where the game essentially gives InputSprocket extra information so that it can behave better. It does this by providing multiple needs, of different data kinds, to change the same thing in the game state. An example where this is useful is for the traditional rudder controls on a flight-sim. Typically, the keyboard commands to change the rudder are 'Increase Left Rudder', 'Center Rudder', and 'Increase Right Rudder'. Each time either of the 'Increase ...' keys are pressed, the current rudder value is changed. In order to restore the plane back to no rudder, you have to either manually press the keys enough times to get back to center, or press the 'Center Rudder' key. The current 'InputSprocket Keyboard' driver does not allow the user to configure an axis need to three keys like this, so this case calls for using extra needs. In addition to the rudder axis need (for those who have a device such as a rudder or twisting joystick), the game will have three button needs: left rudder, center rudder, and right rudder. The axis need should set the kISpNeedFlag_Axis_AlreadyButton bit in the ISpNeed, flags field and the button needs should set the kISpNeedFlag_Button_AlreadyAxis bit. Another common case for using button and axis types is for a throttle in a flight-sim.

Listing 1 contains the complete list of needs chosen for the sample application. Listing 2 is an excerpt from the sample application which demonstrates using axis and button types to change yaw angle. The kISpNeedFlag_Button_AlreadyDelta bit is also set, because the sample application also reads delta types separately. Typically, delta types are used when the developer wants the 'feel' of using a mouse to be similar to how it typically feels in a first person shooter, like Unreal or Quake.

Listing 1: ISp_Sample.h

This is an excerpt from ISp_Sample.h containing the enumeration
of all the needs.

enum
{
    // primary needs
    
    kNeed_FireWeapon,
    kNeed_NextWeapon,
    kNeed_PreviousWeapon,
    
    kNeed_Roll,
    kNeed_Pitch,
    kNeed_Yaw,
    kNeed_Throttle,
    
    kNeed_StartPause,
    kNeed_Quit,
    
    // secondary needs for alternative input kinds
    
    kNeed_Weapon_MachineGun,
    kNeed_Weapon_Cannon,
    kNeed_Weapon_Laser,
    kNeed_Weapon_Missle,
    kNeed_Weapon_PrecisionBomb,
    kNeed_Weapon_ClusterBomb,
    
    kNeed_Roll_AsDelta,
    kNeed_Pitch_AsDelta,
    kNeed_Yaw_AsDelta,
    
    kNeed_Yaw_Left,
    kNeed_Yaw_Center,
    kNeed_Yaw_Right,
    
    kNeed_Throttle_Min,
    kNeed_Throttle_Decrease,
    kNeed_Throttle_Increase,
    kNeed_Throttle_Max,
    
    kNeed_NeedCount
};

Listing 2: ISp_Sample.c

Input_Initialize
This is an excerpt from Input_Initialize which initializes
the needs array.

    //* we'll init all the player 1 items now 
    //* (everything but quit unless we add a second player)
    tempNeed.playerNum = 1;
    // [snip - code removed from this listing]    
    // Now group 4, which is for changing yaw
    tempNeed.group = 4;

    GetIndString (tempNeed.name, kSTRn_NeedNames, 
                      kNeed_Yaw + 1);
    tempNeed.iconSuiteResourceId = 1000 + kNeed_Yaw;
    tempNeed.theKind = kISpElementKind_Axis;
    tempNeed.theLabel = kISpElementLabel_Axis_Yaw;
    tempNeed.flags = kISpNeedFlag_Axis_AlreadyButton;
    myNeeds[kNeed_Yaw] = tempNeed;
    
    GetIndString (tempNeed.name, kSTRn_NeedNames,
                    kNeed_Yaw_Left + 1);
    tempNeed.iconSuiteResourceId = 1000 + kNeed_Yaw_Left;
    tempNeed.theKind = kISpElementKind_Button;
    tempNeed.theLabel = kISpElementLabel_None;
    tempNeed.flags = kISpNeedFlag_Button_AlreadyAxis | 
                   kISpNeedFlag_Button_AlreadyDelta |
                   kISpNeedFlag_EventsOnly;
    myNeeds[kNeed_Yaw_Left] = tempNeed;
    
    GetIndString (tempNeed.name, kSTRn_NeedNames,
                 kNeed_Yaw_Center + 1);
    tempNeed.iconSuiteResourceId = 1000 + kNeed_Yaw_Center;
    tempNeed.theKind = kISpElementKind_Button;
    tempNeed.theLabel = kISpElementLabel_None;
    tempNeed.flags = kISpNeedFlag_Button_AlreadyAxis | 
                   kISpNeedFlag_Button_AlreadyDelta | 
                   kISpNeedFlag_EventsOnly;
    myNeeds[kNeed_Yaw_Center] = tempNeed;
    
    GetIndString (tempNeed.name, kSTRn_NeedNames, 
                kNeed_Yaw_Right + 1);
    tempNeed.iconSuiteResourceId = 1000 + kNeed_Yaw_Right;
    tempNeed.theKind = kISpElementKind_Button;
    tempNeed.theLabel = kISpElementLabel_None;
    tempNeed.flags = kISpNeedFlag_Button_AlreadyAxis | 
                   kISpNeedFlag_Button_AlreadyDelta | 
                   kISpNeedFlag_EventsOnly;
    myNeeds[kNeed_Yaw_Right] = tempNeed;

Listing 2 also demonstrates the other fields that must be filled in the ISpNeed structure. The name field contains a string to be displayed to the user in the configuration dialog (shown in Figure 1), typically in the popup menus for each device element (although the strings appear directly for keyboard devices). The iconSuiteResourceId field contains the resource ID for an icon family that represents that need. Typically 'ics#' and 'ics8' icons are provided, since all the current drivers only display 16x16 icons. The theKind field determines whether the need is a button, delta, axis, dpad, or something else. The theLabel field is used to give hints to InputSprocket about how the need is used. There will inevitably be needs in every game that are not described by one of the labels in InputSprocket.h, those needs should use the kISpElementLabel_None label. Another bit set in the flags field in this listing is kISpNeedFlag_EventsOnly which tells InputSprocket that it does not have to maintain state information for this need. The group was set at the top of the listing, so that it is the same for all these needs. By convention, all the needs which affect the same game state are set to the same group. The full source for Input_Initialize in ISp_Sample.c uses five groups: changing weapon, roll, pitch, yaw, throttle.

Initialization

There are several InputSprocket functions which will typically be necessary during initialization. First, ISpGetVersion should be used to confirm that InputSprocket is available and of a minimum version for the game. Next, ISpStartup should be called to get InputSprocket up and running. ISpElement_NewVirtualFromNeeds is used to create and allocate virtual elements for each need. Virtual elements are the objects that are used to get events or are polled. Now ISpInit can be called to initialize the 'high-level' interface to InputSprocket. ISpInit provides InputSprocket with the needs list and the previously allocated virtual elements. It is often convenient to get events on an element list, which is just a grouping of (in this case virtual) elements. ISpElementList_New is used to allocate a new elements list and ISpElementList_AddElements is used to add one or more elements. Typically, one element list is used for all the regular button needs and an additional element list is created for each group of buttons which correspond to an axis need. Listing 3 is an excerpt from Input_Initialize which demonstrates all of these functions.

Listing 3: ISp_Sample.c

Input_Initialize
This is an excerpt from Input_Initialize which initializes
InputSprocket with the needs list and builds an element list.

    //* Alright, now that the array is set up, we can call ISp to init stuff
    err = ISpStartup ();
    if (err)
        ErrorAlert("\pCould not Initialize InputSprocket.", err, true);

    //*    Setup the input sprocket elements
    err = ISpElement_NewVirtualFromNeeds(kNeed_NeedCount, 
            myNeeds, gInputElements, 0);
    if (err)
        ErrorAlert("\pCould not create ISp virtual controls from needs.", 
               err, true);

    //*    Init InputSprocket and tell it our needs
    err = ISpInit (kNeed_NeedCount, myNeeds, gInputElements, 
                    kISpSampleCreator, kISpSampleNeedsVersion, 
                    0, ksetl_ISpSample, 0); 
    if (err)
        ErrorAlert("\pCould not initialize high-level ISp.", err, true);

    //* Create a element list containg all the 'normal' buttons (we get events on these)
    err = ISpElementList_New(0, NULL, &gEventsElementList, 0);
    if (err)
        ErrorAlert("\pCould not create button element list.", err, true);
    
    //* we set the refcon to the need enum value, so we can use it later
    //* doing some shortcut error checking for readability
    err  = ISpElementList_AddElements (gEventsElementList, 
                    kNeed_FireWeapon,         1, 
           &gInputElements[kNeed_FireWeapon]);
    err |= ISpElementList_AddElements (gEventsElementList, 
                    kNeed_StartPause,         1, 
           &gInputElements[kNeed_StartPause]);

    err |= ISpElementList_AddElements (gEventsElementList, 
                    kNeed_NextWeapon,         1, 
           &gInputElements[kNeed_NextWeapon]);
    err |= ISpElementList_AddElements (gEventsElementList, 
                    kNeed_PreviousWeapon,     1,
           &gInputElements[kNeed_PreviousWeapon]);

    err |= ISpElementList_AddElements (gEventsElementList, 
                    kNeed_Weapon_MachineGun, 1,
           &gInputElements[kNeed_Weapon_MachineGun]);
    err |= ISpElementList_AddElements (gEventsElementList, 
                    kNeed_Weapon_Cannon,     1, 
           &gInputElements[kNeed_Weapon_Cannon]);
    err |= ISpElementList_AddElements (gEventsElementList, 
                    kNeed_Weapon_Laser,     1, 
           &gInputElements[kNeed_Weapon_Laser]);
    err |= ISpElementList_AddElements (gEventsElementList, 
                    kNeed_Weapon_Missle,     1, 
           &gInputElements[kNeed_Weapon_Missle]);
    err |= ISpElementList_AddElements (gEventsElementList, 
                    kNeed_Weapon_PrecisionBomb,1, 
           &gInputElements[kNeed_Weapon_PrecisionBomb]);
    err |= ISpElementList_AddElements (gEventsElementList, 
                    kNeed_Weapon_ClusterBomb,1, 
           &gInputElements[kNeed_Weapon_ClusterBomb]);

    err |= ISpElementList_AddElements (gEventsElementList, 
                    kNeed_Quit,             1, 
           &gInputElements[kNeed_Quit]);

    if (err)
        ErrorAlert(
      "\pCould not fill button element list. Error number may be inaccurate.", 
       err, true);

Cooperating with Mac OS

By default, InputSprocket assumes that a game has its own method, using traditional Mac OS techniques, to get user input from all mice and keyboards. If a game wants to use InputSprocket for keyboard and/or mouse input, it must enable those classes of device with ISpDevices_ActivateClass. Activating the mouse class will disconnect all mice and trackballs from controlling the cursor, so should only be done while the game is in progress and only if the Mac OS cursor is not necessary to play the game. Activating the keyboard class will prevent the keyboard from generating any Mac OS events, although GetKeys will still function.

The game developer must decide whether to use InputSprocket for mouse and/or keyboard input. Using InputSprocket for mouse input is recommended for games that do not use the Mac OS cursor during play. The primary advantages in this case are that multi-button mice are easily supported and configured, and that the user interface is consistent with other gaming devices. For those game developers who do not already have a method they prefer to get keyboard data, using InputSprocket for this purpose will save time. However, InputSprocket is not an appropriate way to get 'typing' input from the user (such as a message that the user is sending to other players), so the keyboard class should be deactivated and traditional Mac OS means used whenever 'typing' is initiated.

Because InputSprocket assumes control of all the active devices when it is active, it is necessary to suspend it when the application is placed in the background. When the application is placed in the foreground again, InputSprocket may be resumed. It is very important that InputSprocket not be left active when the application is not front-most. These operations are normally performed on the response of a suspend/resume OS event and are performed by the functions ISpSuspend and ISpResume. It is safe to use these functions at other times while the application is front-most if desired. However, a slightly better experience may be possible if just the keyboard and mouse classes are disabled. This way, for example, the 'start' button on a gamepad can still be used to start a game. The sample application takes the latter approach.

Getting User Events

The sample application sets up a element list for all the normal button elements with the refcon value the same as the enum value for that need. This makes taking action based on the event almost trivial, as listing 4 demonstrates. ISpElementList_GetNextEvent is used to get the next event on the queue for the element list. ISpTickle is a way to give time to InputSprocket drivers even if the game does not call WaitNextEvent. It must be called at task level (not interrupt level), but is only required for drivers which must be manually enabled (like speech recognition). It is recommended that all games give time, but it is not necessary. It is also reasonable for a game to limit calls to ISpTickle to a few per second.

Listing 4: ISp_Sample.c

Input_ GetButtonEvents
This function is used to modify the gameState structure
if any of the primary buttons have been pressed. This
function is called as part of the normal game loop.

void    Input_GetButtonEvents (Input_GameState * gameState)
{
    OSStatus            error = noErr;
    ISpElementEvent        event;
    Boolean             wasEvent;
    
    // give time to some non-interrupt driven input drivers (like speech recognition)
    ISpTickle ();
    
    // get all pending events
    do
    {
        error = ISpElementList_GetNextEvent (gEventsElementList, 
                                        sizeof (event), &event, &wasEvent);
        
        if (wasEvent && !error)
        {
            switch (event.refCon)
            {
                case kNeed_FireWeapon:
                    if (event.data == kISpButtonDown)
                    {
                        gameState->fireWeaponState = true;
                        gameState->fireWeaponCount++;
                    }
                    else // (event.data == kISpButtonUp)
                        gameState->fireWeaponState = false;
                    break;
                    
                case kNeed_StartPause:
                    if (event.data == kISpButtonDown)
                    {
                        if (!gameState->gameInProgress)
                            gameState->gameInProgress = true;
                        else
                            gameState->gamePaused = 
                                !gameState->gamePaused;
                    }
                    break;
                    
                case kNeed_NextWeapon:
                    if (event.data == kISpButtonDown)
                    {
                        gameState->currentWeapon++;
                        if (gameState->currentWeapon >= 
                                    kWeapon_WeaponCount)
                            gameState->currentWeapon = 0;
                    }
                    break;
                    
                case kNeed_PreviousWeapon:
                    if (event.data == kISpButtonDown)
                    {
                        gameState->currentWeapon-;
                        if (gameState->currentWeapon < 0)
                            gameState->currentWeapon = 
                                    kWeapon_WeaponCount - 1;
                    }
                    break;
                    
                case kNeed_Weapon_MachineGun:
                    if (event.data == kISpButtonDown)
                        gameState->currentWeapon = kWeapon_MachineGun;
                    break;
                    
                case kNeed_Weapon_Cannon:
                    if (event.data == kISpButtonDown)
                        gameState->currentWeapon = kWeapon_Cannon;
                    break;
                    
                case kNeed_Weapon_Laser:
                    if (event.data == kISpButtonDown)
                        gameState->currentWeapon = kWeapon_Laser;
                    break;
                    
                case kNeed_Weapon_Missle:
                    if (event.data == kISpButtonDown)
                        gameState->currentWeapon = kWeapon_Missle;
                    break;
                    
                case kNeed_Weapon_PrecisionBomb:
                    if (event.data == kISpButtonDown)
                        gameState->currentWeapon = 
                            kWeapon_PrecisionBomb;
                    break;
                    
                case kNeed_Weapon_ClusterBomb:
                    if (event.data == kISpButtonDown)
                        gameState->currentWeapon = kWeapon_ClusterBomb;
                    break;
                    
                case kNeed_Quit:
                    gameState->gameInProgress = false;
                    break;
            }
        }
    }
    while (wasEvent && !error);
}

Polling Axis Values

The sample application reads axis values for roll, pitch, yaw, and throttle. The most complicated one is yaw, which is shown in listing 5. When there are both an axis and button needs that map to the same game state, there is an easy technique to get the correct behavior. First, ISpElement_GetNextEvent is used on the axis element just to check to see if the axis value changed. If it did change, then ISpElement_GetSimpleState is used to poll the current value of that axis element. Both the axis element and the element list are then flushed. However, if the axis value has not changed (wasEvent is false), then ISpElementList_GetNextEvent is used to get all the button events on the element list containing the buttons for the axis. Delta values are actually handled differently at a higher level, so they are read and accumulated into a separate value in the state structure.

Listing 5: ISp_Sample.c

Input_GetYaw
This function is used to modify the gameState structure to include
the latest changes in yaw based on user input. This function is
called as part of the normal game loop.

void    Input_GetYaw (Input_GameState * gameState)
{
    OSStatus                    error = noErr;
    ISpElementEvent        event;
    Boolean                     wasEvent;
    ISpAxisData            axisValue;
    SInt32                        yawValue = gameState->yawInput;
    
    // we check the axis, to see if _it_ was moved, if so, we use that value
    error = ISpElement_GetNextEvent (gInputElements[kNeed_Yaw], 
                    sizeof (event), &event, &wasEvent);
    if (!error && wasEvent)
    {
        // we wish to ignore all button presses _prior_ to this moment
        ISpElementList_Flush(gYawElementList);

        // get the current value
        error = ISpElement_GetSimpleState 
                                    (gInputElements[kNeed_Yaw], &axisValue);
        if (!error) 
            yawValue = 
                ISpAxisToSampleAxis (axisValue, kMin_Yaw, kMax_Yaw);

        ISpElement_Flush(gInputElements[kNeed_Yaw]);
    }
    // otherwise, we check to see if one of the yaw buttons was pressed
    else do
    {
        error = ISpElementList_GetNextEvent (gYawElementList,
                                     sizeof (event), &event, &wasEvent);
        
        // only process valid keydown events (all the yaw events ignore button ups)
        if (wasEvent && !error && (event.data == kISpButtonDown))
        {
            switch (event.refCon)
            {
                case kNeed_Yaw_Left:
                    yawValue -= kIncrement_Yaw;
                    if (yawValue < kMin_Yaw) yawValue = kMin_Yaw; 
                    break;
                case kNeed_Yaw_Center:
                    yawValue = kMin_Yaw + ((kMax_Yaw - kMin_Yaw) / 2);
                    break;
                case kNeed_Yaw_Right:
                    yawValue += kIncrement_Yaw;
                    if (yawValue > kMax_Yaw) yawValue = kMax_Yaw; 
                    break;
            }
        }
    }
    while (wasEvent && !error);
    
    gameState->yawInput = yawValue;
    
    //* also check the delta values
    gameState->deltaYaw = 0;
    do
    {
        error = ISpElement_GetNextEvent
                         (gInputElements[kNeed_Yaw_AsDelta], 
                            sizeof (event), &event, &wasEvent);
        if (wasEvent && !error)
            gameState->deltaYaw += (Fixed) event.data;
    }
    while (wasEvent && !error);
}

InputSprocket Resources

InputSprocket checks for certain resources inside an application. First, the application should have an InputSprocket application resource ('isap') which simply specifies how the application uses InputSprocket. Next, the application should have a set list resource ('setl'). It is ok if there are no sets contained in this resource, but it should be present. The set list resource contains pointers to individual saved-set resources ('tset'). Saved set resources contain a set of configuration information for a single device for a specific application. InputSprocket.r contains a resource template for a saved-set resource that corresponds to a keyboard device. This template can be used to put keyboard defaults in a '.r' file. The saved set resources for all the other devices do not have templates. This means that the developer must execute the built game, manually create each set he wants to include with the game, and then copy these sets from the active 'Input Sprocket Preferences' file (in the Preferences folder) to his '.r' file. The sample application includes two sets for the keyboard and two for the mouse. Fortunately the default settings for most drivers (other than the keyboard) are pretty good if the developer is careful about ordering his needs list, so it is usually not necessary to provide sets besides those for the keyboard. Listing 6 contains the resource description for the default keyboard set in the sample application. If the keyboard saved set resource does not have the correct number of items, then it will not function even though it may still be displayed in the sets menu. The easiest way to debug this is to compare a saved set resource generated by a '.r' file with one created by the 'InputSprocket Keyboard' driver in the 'InputSprocket Preferences' file. Also note that the default sets are only copied once from the application to the 'InputSprocket Preferences' file, so it usually will be necessary to delete the 'InputSprocket Preferences' file from the preferences folder several times during development.

Listing 5: ISp_Sample.r

ktset_DefaultKeyboard
This is the resource description for the default keyboard
set in the sample application.

#define        rNoModifiers    rControlOff, rOptionOff, rShiftOff, \
                   controlOff, optionOff, shiftOff, commandOff
 
resource 'tset' (ktset_DefaultKeyboard, "Default (Keyboard)")
{
    supportedVersion,
    {    
        /* kNeed_FireWeapon */
        kpd0Key, rNoModifiers,
        
        /* kNeed_NextWeapon */
        kpd9Key, rNoModifiers,
        
        /* kNeed_PreviousWeapon */
        kpd7Key, rNoModifiers,
        
        /* kNeed_Roll */
        /* min (left/down/back) */
        kpd4Key, rNoModifiers,
         
        /* max (right/up/forward) */
        kpd6Key, rNoModifiers,

        /* kNeed_Pitch */
        /* min (left/down/back) */
        kpd5Key, rNoModifiers,
         
        /* max (right/up/forward) */
        kpd8Key, rNoModifiers,
        
        /* kNeed_Yaw */
    /* this need does not generate any items, because it has later button equivalents */
        /* kNeed_Throttle */
    /* this need does not generate any items, because it has later button equivalents */
    
        /* kNeed_StartPause */
        tildeKey, rNoModifiers,
        
        /* kNeed_Quit */
        qKey, rControlOff, rOptionOff, rShiftOff, 
         controlOff, optionOff, shiftOff, commandOn,
        
        /* kNeed_Weapon_MachineGun */
        n1Key, rNoModifiers,
        /* kNeed_Weapon_Cannon */
        n2Key, rNoModifiers,
        /* kNeed_Weapon_Laser */
        n3Key, rNoModifiers,
        /* kNeed_Weapon_Missle */
        n4Key, rNoModifiers,
        /* kNeed_Weapon_PrecisionBomb */
        n5Key, rNoModifiers,
        /* kNeed_Weapon_ClusterBomb */
        n6Key, rNoModifiers,

        /* kNeed_Roll_AsDelta */
        /* this need does not generate any items - the keyboard does not do deltas */
        /* kNeed_Pitch_AsDelta */
        /* this need does not generate any items - the keyboard does not do deltas */
        /* kNeed_Yaw_AsDelta */
        /* this need does not generate any items - the keyboard does not do deltas */

        /* kNeed_Yaw_Left */
        aKey, rNoModifiers,
        /* kNeed_Yaw_Center */
        sKey, rNoModifiers,
        /* kNeed_Yaw_Right */
        dKey, rNoModifiers,

        /* kNeed_Throttle_Min */
        kpdEqualKey, rNoModifiers,
        /* kNeed_Throttle_Decrease */
        kpdMinusKey, rNoModifiers,
        /* kNeed_Throttle_Increase */
        kpdPlusKey, rNoModifiers,
        /* kNeed_Throttle_Max */
        kpdSlashKey, rNoModifiers,

    };
};

Final Word

Using InputSprocket for user input in games is a good idea. It is relatively simple to implement, and both the developer and game player benefit. With the introduction of the iMac, and its USB ports, the number of input devices available to Macintosh customers is ballooning. At the time this was written, the current version of InputSprocket was 1.4. The latest version and information is available at http://developer.apple.com/games/sprockets. Examining the sample application, which was written using the techniques in this article, should be the next step for a developer interested in using InputSprocket. The finished application is pictured in Figure 2.


Figure 2. ISp_Sample in action.


Brent Schorsch is the engineer at Apple Computer, Inc. responsible for InputSprocket. Brent enjoys reading science fiction novels, reading a dozen or so books a month. In addition, Brent is an avid game enthusiast. His favorite games are those that can be played against human opponents. In such battles, he answers to the handle 'Ender' which he acquired playing Bungie's 'Minotaur' back in the dark ages. You might find him online on iMagicOnline's WWII flight-sim, Warbirds, using the handle '-endr-' flying for purple.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »

Price Scanner via MacPrices.net

New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more
Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Apple’s standard one-year warranty... Read more

Jobs Board

DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
IT Systems Engineer ( *Apple* Platforms) - S...
IT Systems Engineer ( Apple Platforms) at SpaceX Hawthorne, CA SpaceX was founded under the belief that a future where humanity is out exploring the stars is Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.