Skip to content

Commit

Permalink
feat: use e.altkey instaed of key
Browse files Browse the repository at this point in the history
use event.altKey to check alt key pressed for support linux (and more compatibility)

close raunofreiberg#2
  • Loading branch information
iamchanii committed Apr 28, 2021
1 parent 7c6dcd4 commit 188a2af
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ export default function Inspect({
const nodesAtPointerRef = React.useRef<HTMLElement[]>([]);

React.useEffect(() => {
let altKeyPressed = false;

function onKeyDown(e: KeyboardEvent) {
if (e.key === 'Alt') {
if (e.altKey) {
altKeyPressed = true;
if (margin) inspectMargin(nodesAtPointerRef.current);
if (size) inspectSize(nodesAtPointerRef.current);
if (padding) inspectPadding(nodesAtPointerRef.current);
}
}

function onKeyUp(e: KeyboardEvent) {
if (e.key === 'Alt') {
function onKeyUp() {
if (altKeyPressed) {
altKeyPressed = false;
uninspect();
}
}
Expand Down

0 comments on commit 188a2af

Please sign in to comment.