@@ -5,18 +5,118 @@ React Native listen event from external keyboard
55## Installation
66
77``` sh
8- npm install react-native-external-keyboard-listener
8+ npm install react-native-external-keyboard-listener OR yarn add
9+
10+ npx pod-install
11+ ```
12+
13+ ### Permissions
14+
15+ - Android: Add these lines to your AndroidManifest.xml:
16+ ``` xml
17+ <manifest xmlns : android =" http://schemas.android.com/apk/res/android" >
18+ ...
19+
20+ <!-- Android >= 12 -->
21+ <uses-permission android : name =" android.permission.BLUETOOTH_SCAN" />
22+ <uses-permission android : name =" android.permission.BLUETOOTH_CONNECT" />
23+ <!-- Android < 12 -->
24+ <uses-permission android : name =" android.permission.BLUETOOTH" android : maxSdkVersion =" 30" />
25+ <uses-permission android : name =" android.permission.BLUETOOTH_ADMIN" android : maxSdkVersion =" 30" />
26+ <!-- common -->
27+ <uses-permission android : name =" android.permission.ACCESS_FINE_LOCATION" android : maxSdkVersion =" 30" />
28+
29+ <!-- Add this line if your application always requires BLE. More info can be found on:
30+ https://developer.android.com/guide/topics/connectivity/bluetooth-le.html#permissions
31+ -->
32+ <uses-feature android : name =" android.hardware.bluetooth_le" android : required =" true" />
33+
34+ ...
35+ ```
36+
37+ - iOS: Add this key to your Info.plist:
38+ ``` xml
39+ <key >NSBluetoothAlwaysUsageDescription</key >
40+ <string >This app requires Bluetooth access</string >
941```
1042
1143## Usage
1244
45+ ## API Reference
46+
47+ ### ` startListening() `
48+ • Signature: ` startListening(): void `
49+ • Description: Begins listening for external keyboard events, emitting callbacks such as “OnKeyPress” or “KeyboardConnectionChanged.”
50+ • Example:
51+ ``` tsx
52+ ExternalKeyboardListenerEmitter .startListening ();
53+ ```
54+
55+ ---
56+
57+ ### ` stopListening() `
58+ • Signature: ` stopListening(): void `
59+ • Description: Stops listening for external keyboard events and releases related resources.
60+ • Example:
61+ ``` tsx
62+ ExternalKeyboardListenerEmitter .stopListening ();
63+ ```
64+
65+ ---
66+
67+ ### ` checkKeyboardConnection() `
68+ • Signature: ` checkKeyboardConnection(): Promise<boolean> `
69+ • Description: Checks if an external keyboard is present.
70+ • Example:
71+ ``` tsx
72+ const isConnected = await ExternalKeyboardListenerEmitter .checkKeyboardConnection ();
73+ console .log (' Keyboard connected:' , isConnected );
74+ ```
75+
76+ ---
77+
78+ ### ` isBluetoothEnabled() `
79+ • Signature: ` isBluetoothEnabled(): Promise<boolean> `
80+ • Description: Check if Bluetooth is enabled or not
81+ • Example:
82+ ``` tsx
83+ await ExternalKeyboardListenerEmitter .isBluetoothEnabled ();
84+ ```
85+
86+ ---
87+
88+ ### ` enableBluetooth() `
89+ • Signature: ` enableBluetooth(): Promise<void> `
90+ • Description: Opens system Bluetooth settings to allow enabling Bluetooth.
91+ • Example:
92+ ``` tsx
93+ await ExternalKeyboardListenerEmitter .enableBluetooth ();
94+ ```
95+
96+ ---
97+
98+ ### ` requestBluetoothPermission() `
99+ • Signature: ` requestBluetoothPermission(): Promise<boolean> `
100+ • Description: Requests Bluetooth permissions on Android.
101+ • Example:
102+ ``` tsx
103+ const granted = await ExternalKeyboardListenerEmitter .requestBluetoothPermission ();
104+ console .log (' Permission granted:' , granted );
105+ ```
13106
14- ``` js
15- import { multiply } from ' react-native-external-keyboard-listener' ;
107+ ---
16108
17- // ...
109+ ### ` startKeyPressListener(callback: (event: KeyPressEvent) => void) `
110+ • Signature: ` startKeyPressListener(callback: (event: KeyPressEvent) => void): { remove: () => void } `
111+ • Description: Subscribes to key press events from an external keyboard.
112+ • Example:
113+ ``` tsx
114+ const subscription = ExternalKeyboardListenerEmitter .startKeyPressListener ((evt ) => {
115+ console .log (' Key pressed:' , evt );
116+ });
18117
19- const result = await multiply (3 , 7 );
118+ // Stop listening:
119+ subscription .remove ();
20120```
21121
22122
0 commit comments