Skip to content

Commit

Permalink
Add KeyboardListener to viewer page
Browse files Browse the repository at this point in the history
  • Loading branch information
TaYaKi71751 committed Dec 23, 2023
1 parent 09d827d commit e425982
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/pages/viewer/horizontal_viewer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class HorizontalViewerPage extends StatefulWidget {

class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
late final ViewerController c;
Duration? lastKeyPressedTimeStamp;

@override
void initState() {
Expand Down Expand Up @@ -76,6 +77,27 @@ class _HorizontalViewerPageState extends State<HorizontalViewerPage> {
),
),
),
KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
if(lastKeyPressedTimeStamp != null){
print('${event.timeStamp.inSeconds}');
print('${lastKeyPressedTimeStamp!.inSeconds}');
// print(event.timeStamp.inSeconds - lastKeyPressedTimeStamp!.inSeconds);
if((event.timeStamp.inMilliseconds - lastKeyPressedTimeStamp!.inMilliseconds) < 250) return;
}
lastKeyPressedTimeStamp = event.timeStamp;
if(event.physicalKey.debugName == 'Arrow Left'){
c.leftButton();
// print(event.timeStamp.toString());
}
if(event.physicalKey.debugName == 'Arrow Right'){
c.rightButton();
// print(event.timeStamp.toString());
}
},
child: Container(),
),
Align(
alignment: Alignment.center,
child: Container(
Expand Down

0 comments on commit e425982

Please sign in to comment.