MATLAB Python

getInputDevice

Syntax

[input_device_id, found_inputs] = getInputDevice(input [,device_type] [,strict_matching]) [] = optional parameters

Description

This function takes a deviceID, full or partial device name, full serial number, or full productID, and searches for a matching device based on the inputs available at runtime. Multiple input devices can be specified in a cell array, with preferred devices listed first. This can be useful for code designed to run on multiple machines, or laptops where external devices may or may not be present. Loose matching when specifying a full or partial device name requires preliminary info about the device gathered through a call to GETINPUTDEVICE with no parameters. An optional string or cell array can be provided to limit matching to a particular type or set of device types (any of 'keyboard', 'mouse', 'keypad', 'gamepad', 'audio', or 'unknown'). Order preference is taken into account for this list as well. Note: device matching in this way is not guaranteed to produce the correct device of its class. An optional boolean can be provided for strict matching (case sensitive, exact match) rather than loose matching (case insensitive, partial match; default case). If no matches are found, an error is returned. If multiple matches are found (due to an ambiguous input name), a best guess at the desired device among the matches will be selected. This guess involves preference for devices of the correct category, for devices matching encouraging strings, and for attached over internal devices (because it's probably attached for a reason). It includes preference against devices that match known pitfalls (e.g., "virtual" keyboard on unix). If empty input is specified, the default (-1) is returned.

Usage

To produce a list of all currently available inputs, call the function without any arguments, i.e., getInputDevice() . getInputDevice(): print a table of all available input devices. [~, available] = getInputDevice(): catch this table. [id, available] = getInputDevice([],'mouse'): get a table of all mice, returning the first mouse found as an id. id = getInputDevice(2): check that 2 corresponds to an available device. id = getInputDevice(2,'keyboard'): check that 2 corresponds to an available keyboard. id = getInputDevice('internal','keyboard'): get the device ID of a laptop's internal keyboard using partial name matching and a little optimism. id = getInputDevice('Apple Internal Keyboard Trackpad','keyboard',true): strict matching to my laptop's internal keyboard. id = getInputDevice({'fmri','internal'}): match either an fMRI input or internal keyboard, giving priority to the fMRI input, so that we choose the scanner's input when it is available.

Output

Outputs consists of the validated deviceID, and a table containing detailed information about all matching inputs.