Skip to content

Commit

Permalink
replace globalKeyStateTracker with KeyboardListener, see phetsims/sce…
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Nov 18, 2022
1 parent b8361ec commit c4560b5
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions js/micro/view/MicroScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransfo
import ResetAllButton from '../../../../scenery-phet/js/buttons/ResetAllButton.js';
import PhetFont from '../../../../scenery-phet/js/PhetFont.js';
import TimeControlNode from '../../../../scenery-phet/js/TimeControlNode.js';
import { AriaHasPopUpMutator, globalKeyStateTracker, KeyboardUtils, Node, Rectangle, Text } from '../../../../scenery/js/imports.js';
import { AriaHasPopUpMutator, KeyboardListener, Node, Rectangle, Text } from '../../../../scenery/js/imports.js';
import RectangularPushButton from '../../../../sun/js/buttons/RectangularPushButton.js';
import Dialog from '../../../../sun/js/Dialog.js';
import nullSoundPlayer from '../../../../tambo/js/shared-sound-players/nullSoundPlayer.js';
Expand Down Expand Up @@ -225,24 +225,25 @@ class MicroScreenView extends ScreenView {

// Alternative Input - no matter where focus is in the document, pressing Alt+L will manually step forward
// in time
const globalKeyboardListener = event => {
if (
timeControlNode.pdomDisplayed &&
!photonAbsorptionModel.runningProperty.get() &&
globalKeyStateTracker.altKeyDown &&
KeyboardUtils.isKeyEvent( event, KeyboardUtils.KEY_L ) ) {

// The global hotkey step has a larger time step so that it is easier for the photon to reach the molecule
// and provide feedback for a non-visual experience. The timeStep is calculated so that a photon can never
// move farther than the absorption window of a molecule in a single step and pass over the molecule without
// checking for absorption.
const timeStep = 2 * Molecule.PHOTON_ABSORPTION_DISTANCE / PhotonAbsorptionModel.PHOTON_VELOCITY;
photonAbsorptionModel.manualStep( timeStep );

stepForwardSoundPlayer.play();
const keyboardListener = new KeyboardListener( {
keys: [ 'alt+l' ],
global: true,
fireOnKeyUp: true,
callback: ( event, listener ) => {
if ( !photonAbsorptionModel.runningProperty.get() ) {

// The global hotkey step has a larger time step so that it is easier for the photon to reach the molecule
// and provide feedback for a non-visual experience. The timeStep is calculated so that a photon can never
// move farther than the absorption window of a molecule in a single step and pass over the molecule without
// checking for absorption.
const timeStep = 2 * Molecule.PHOTON_ABSORPTION_DISTANCE / PhotonAbsorptionModel.PHOTON_VELOCITY;
photonAbsorptionModel.manualStep( timeStep );

stepForwardSoundPlayer.play();
}
}
};
globalKeyStateTracker.keyupEmitter.addListener( globalKeyboardListener );
} );
timeControlNode.addInputListener( keyboardListener );

// the light spectrum dialog and emission frequency control panel are removed in the
// Open Sci Ed version
Expand Down

0 comments on commit c4560b5

Please sign in to comment.