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

@thegreatzeus/expo-keyevent

v0.3.0

Published

Native key and gamepad events for React Native and Expo

Readme

@thegreatzeus/expo-keyevent

A powerful Expo module that allows you to globally listen and react to hardware keyboard events (onKeyDown and onKeyUp) on both iOS and Android.

Additionally, on iOS, this package natively captures input from the GameController framework, meaning button presses and D-pad inputs from connected game controllers will automatically trigger the same key events, completely seamlessly!

Installation

npm install @thegreatzeus/expo-keyevent
# or
yarn add @thegreatzeus/expo-keyevent

Note: As this package includes native code, you will need to create a custom development build (using npx expo run:ios or npx expo run:android) or use EAS Build. This module will not work in the standard Expo Go app.

Usage

Here is a simple example showing how to listen to key presses and releases in your application:

import { useEffect } from 'react';
import { SafeAreaView, Text, View } from 'react-native';
import { useEvent } from 'expo';
import ExpoKeyevent from '@thegreatzeus/expo-keyevent';

export default function App() {
  // Hook into the native key events
  const onKeyDownPayload = useEvent(ExpoKeyevent, 'onKeyDown');
  const onKeyUpPayload = useEvent(ExpoKeyevent, 'onKeyUp');

  useEffect(() => {
    // Start listening for specific key events.
    // In this example, we listen to Space (62) and Enter (66), and consume them.
    ExpoKeyevent.startListening({
      listenAll: false,
      consumeEvents: true,
      keyCodes: [62, 66],
      keys: [' ']
    });
    
    return () => {
      // Don't forget to stop listening when the component unmounts
      ExpoKeyevent.stopListening();
    };
  }, []);

  return (
    <SafeAreaView style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Text style={{ fontSize: 24, fontWeight: 'bold' }}>ExpoKeyEvent Example</Text>
      
      <View style={{ marginTop: 20 }}>
        <Text>Last Key Down: {onKeyDownPayload ? `${onKeyDownPayload.key} (Code: ${onKeyDownPayload.keyCode})` : 'None'}</Text>
        <Text>Last Key Up: {onKeyUpPayload ? `${onKeyUpPayload.key} (Code: ${onKeyUpPayload.keyCode})` : 'None'}</Text>
      </View>
    </SafeAreaView>
  );
}

API Reference

startListening(config?: KeyeventConfig)

Starts observing key events globally on the native window/application.

The KeyeventConfig object accepts the following properties:

  • listenAll (boolean, optional): If true, listens to all key events. Defaults to true if no config is provided.
  • consumeEvents (boolean, optional): If true, the native framework will consume the matched key events so they are not propagated down to the rest of the application's native views (like scrolling scrollviews, triggering default button actions, etc.). Default is false.
  • keyCodes (number[], optional): A list of specific native integer key codes to listen for.
  • keys (string[], optional): A list of specific key characters to listen for.

Note: You cannot set listenAll to true while also providing keyCodes or keys. The module will throw an error if you attempt to activate both modes simultaneously.

stopListening()

Stops observing key events. Always ensure you call this during cleanup (e.g., in a useEffect return block) to prevent memory leaks or duplicate event dispatches.


Events

You can listen to events using Expo's useEvent hook, or via standard listeners: ExpoKeyevent.addListener('onKeyDown', callback).

onKeyDown

Triggered when a key is pressed down, or when a game controller button is pressed (iOS).

onKeyUp

Triggered when a key is released, or when a game controller button is released (iOS).

Payload Type (KeyEventPayload)

Both onKeyDown and onKeyUp events provide a payload of type KeyEventPayload:

export type KeyEventPayload = {
  key: string;           // The character or localized name of the key/button (e.g., "a", "Enter", "Button A", "D-Pad Up")
  keyCode: number;       // The native integer code representing the key. Note: Game controllers on iOS will return 0.
  modifierFlags: number; // Bitmask of modifier keys (e.g., Shift, Ctrl) pressed alongside the key.
};

Gamepad API Support (iOS)

On iOS, the module is tightly integrated with the native GameController framework. When startListening() is called, it will automatically connect to existing and newly discovered Gamepads (e.g. Xbox, PlayStation, MFi controllers).

Button presses (like Button A, Button X) and D-Pad interactions are piped directly into the onKeyDown and onKeyUp events. The payload's key property will resolve to a readable string based on the button's native localized name (such as "Button A" or "D-Pad Down").