Dear Mario & friends
I pasted below a routine that I wrote years ago to discover whether
the user has recently attached a wireless keyboard, Its first step
is to clear PsychHID. However, Mario has discouraged us from doing that.
Can you suggest a better way of forcing a fresh enumeration of keyboards?
The situation is that only after my big psychophysical testing program is running, we realize that that we need a long viewing distance that requires a wireless keyboard, so we ask the user to attach it, and then call this routine to get the computer to talk to the new keyboard. This call to clear PsychHID was working, but now itâs a problem because now I also use ColorCal2.m to read the CRS Colorimeter, and ColorCal2 uses PsychHID, and fails after I clear PsychHID.
Best
Denis
model: 'MacBookPro14,3'
modelDescription: 'MacBook Pro (15-inch, 2017)'
manufacturer: 'Apple Inc.'
psychtoolbox: 'Psychtoolbox 3.0.16'
matlab: 'MATLAB 9.8 (R2020a)'
system: 'macOS 10.14.6'
screenMex: 'Screen.mexmaci64 Apr 26 2020'
screens: 0
screen: {[0]}
size: {[2560 1600]}
nativeSize: {[2880 1800]}
mm: {[331 207]}
openGLRenderer: {'AMD Radeon Pro 560 OpenGL Engine'}
openGLVendor: {'ATI Technologies Inc.'}
openGLVersion: {'2.1 ATI-2.11.21'}
psychtoolboxKernelDriver: âPsychtoolboxKernelDriver 1.1â
drawTextPlugin: 1
psychPortAudio: 1
summary: âMacBookPro14,3-macOS-10.14.6-PTB-3.0.16â
function [hasWirelessKeyboard,keyboardNameAndTransport]=HasWirelessKeyboard
% [hasWirelessKeyboard,keyboardNameAndTransport]=HasWirelessKeyboard;
%
% Forces new enumeration of devices and returns a logical value reporting
% whether there is an active wireless keyboard.
%
% A WIRELESS OR LONG-CABLE KEYBOARD is highly desirable because a normally
% sighted observer viewing foveally has excellent vision and must be many
% meters away from the screen in order for us to measure her acuity limit.
% At this distance she canât reach the built-in keyboard attached
% to the screen. If you must use the built-in keyboard, then have the
% experimenter type the observerâs verbal answers. Instead, I like the
% Logitech K760 solar-powered wireless keyboard, because its batteries
% never run out. Itâs no longer made, but still available on Amazon, New
% Egg, and eBay (below). To âpairâ the keyboard with your computerâs blue
% tooth, press the tiny button on the back of the keyboard.
%
% Logitech Wireless Solar Keyboard K760 for Mac/iPad/iPhone
% http://www.amazon.com/gp/product/B007VL8Y2C
% https://www.newegg.com/logitech-wireless-solar-keyboard-k760-bluetooth-wireless/p/N82E16823126283?Item=9SIA4RE7ZV9401
% https://www.ebay.com/sch/i.html?_from=R40&_trksid=m570.l1313&_nkw=Logitech+K760+Wireless+Solar+Keyboard+&_sacat=0
% https://www.logitech.com/assets/44407/wireless-solar-keyboard-k760-quickstart-guide.pdf
%
% See also: RequestWirelessKeyboard.
%
% denis.pelli@nyu.edu, May, 2019.
if IsWin
hasWirelessKeyboard=[]; % Impossible to find out on Windows.
keyboardNameAndTransport={};
return
end
% Force new enumeration of devices to detect newly attached external
% keyboard.
clear PsychHID;
% Clear cache of keyboard devices.
clear KbCheck;
[~,~,devices]=GetKeyboardIndices;
for i=1:length(devices)
keyboardNameAndTransport{i}=sprintf(â%s (%s)â,devices{i}.product,devices{i}.transport);
end
hasWirelessKeyboard=length(GetKeyboardIndices)>=2 âŚ
|| contains(lower(keyboardNameAndTransport{1}),âwirelessâ) âŚ
|| contains(lower(keyboardNameAndTransport{1}),âbluetoothâ);
end