npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

expo-key-event

v1.8.3

Published

Provides an interface for reading key events such as from external bluetooth keyboards on Android, iOS and Web.

Readme

Supported platforms

  • iOS
  • Android
  • Web
  • macOS (Mac Catalyst & react-native-macos)

Requirements

Expo SDK >= 52

Getting started

npm i expo-key-event

Usage

Basic

Automatic listening: Key events are listened to as soon as MyComponent is mounted.

import { useKeyEvent } from "expo-key-event";
import { Text } from "react-native";

export function MyComponent() {
  const { keyEvent } = useKeyEvent();

  return <Text>{keyEvent?.key}</Text>;
}

Control listening

Manual listening: Key events are listened to when startListening is called.

import { useKeyEvent } from "expo-key-event";
import { Text, View } from "react-native";

export function MyComponent() {
  // deprecated way
  // const { keyEvent, startListening, stopListening } = useKeyEvent(false);
  // new way
  const { keyEvent, keyReleaseEvent, startListening, stopListening } =
    useKeyEvent({ listenOnMount: false });

  return (
    <View>
      <Text>{keyEvent?.key}</Text>
      <Button title="Start listening" onPress={() => startListening()} />
      <Button title="Stop listening" onPress={() => stopListening()} />
    </View>
  );
}

Using event listener

Handling state yourself: If you want to handle the state yourself or don't need the state at all, you can use the useKeyEventListener hook instead of the useKeyEvent hook.

import { KeyPressEvent, useKeyEventListener } from "expo-key-event";
import { Text, View } from "react-native";

export function MyComponent() {
  const [keyEvent, setKeyEvent] = useState<KeyPressEvent>();
  // deprecated way
  // const { startListening, stopListening } = useKeyEventListener((event) => {
  //   setKeyEvent(event);
  // }, automaticControl);
  // new way
  const { startListening, stopListening } = useKeyEventListener(
    (event) => {
      setKeyEvent(event);
    },
    {
      listenOnMount: automaticControl,
    }
  );

  return (
    <View>
      <Text>{keyEvent?.key}</Text>
      <Button title="Start listening" onPress={() => startListening()} />
      <Button title="Stop listening" onPress={() => stopListening()} />
    </View>
  );
}

Modifier keys

Using modifier keys: Key events include modifier key states (shift, ctrl, alt, meta) and repeat information when captureModifiers is enabled.

import { useKeyEvent } from "expo-key-event";
import { Text, View } from "react-native";

export function MyComponent() {
  const { keyEvent } = useKeyEvent({
    listenOnMount: true,
    captureModifiers: true, // Enable modifier key capture
  });

  return (
    <View>
      <Text>Key: {keyEvent?.key}</Text>
      <Text>Shift: {keyEvent?.shiftKey ? "Yes" : "No"}</Text>
      <Text>Ctrl: {keyEvent?.ctrlKey ? "Yes" : "No"}</Text>
      <Text>Alt: {keyEvent?.altKey ? "Yes" : "No"}</Text>
      <Text>Meta: {keyEvent?.metaKey ? "Yes" : "No"}</Text>
      <Text>Repeat: {keyEvent?.repeat ? "Yes" : "No"}</Text>
    </View>
  );
}

Modifier key combinations

Checking for specific key combinations:

import { useState } from "react";
import { KeyPressEvent, useKeyEventListener } from "expo-key-event";
import { Text } from "react-native";

export function MyComponent() {
  const [message, setMessage] = useState("");

  useKeyEventListener(
    (event: KeyPressEvent) => {
      // Check for Cmd+S (macOS) or Ctrl+S (Windows/Linux)
      if (event.key === "KeyS" && (event.metaKey || event.ctrlKey)) {
        setMessage("Save shortcut pressed!");
      }
      // Check for Shift+Enter
      else if (event.key === "Enter" && event.shiftKey) {
        setMessage("New line!");
      }
      // Check for Alt+Arrow
      else if (event.key === "ArrowRight" && event.altKey) {
        setMessage("Navigate forward!");
      }
    },
    {
      listenOnMount: true,
      captureModifiers: true, // Required to receive modifier key states
    }
  );

  return <Text>{message}</Text>;
}

Run example app

cd example

npm run ios / npm run android / npm run web

Troubleshooting

_expo.useEvent is not a function

This is most likely due to using Expo SDK lower than 52. useEvent was introduced in SDK 52.

Error: Cannot find native module 'ExpoKeyEvent'

Make sure to use a development build and not Expo Go. See https://docs.expo.dev/guides/local-app-development/ for more details.

In short: Use npx expo run:ios instead of npx expo start (make sure bundleIdentifier is set in app.json).

Key events are not registered in iOS simulator

Make sure that hardware keyboard is connected to the simulator.

Key events are not registered in Android emulator

Since the Android emulator does not support USB or Bluetooth, you need to use a physical device so that key events can be registered.

Another option is to use adb to send key events to the emulator.

e.g. adb shell input keyevent 10

How it works

This module translates the Apple UIKit and Android KeyEvent constants to a common set of key event types matching the ones from Web.