Browse Source

Allow playing/pausing with spacebar

master
Dylan Baker 3 years ago
parent
commit
05e950922f
1 changed files with 9 additions and 1 deletions
  1. 9
    1
      src/Controls.tsx

+ 9
- 1
src/Controls.tsx View File

@@ -1,4 +1,4 @@
1
-import React from 'react';
1
+import React, { useEffect } from 'react';
2 2
 
3 3
 interface Props {
4 4
   running: boolean;
@@ -33,6 +33,14 @@ const Controls = (props: Props) => {
33 33
     }
34 34
   };
35 35
 
36
+  useEffect(() => {
37
+    document.addEventListener('keyup', (e) => {
38
+      if (e.key === ' ') {
39
+        toggle();
40
+      }
41
+    });
42
+  }, [toggle]);
43
+
36 44
   return (
37 45
     <div className="controls">
38 46
       <div className="controls__section dimensions">

Loading…
Cancel
Save