-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
85 lines (81 loc) · 2.1 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { useState, useEffect } from 'react'
import { StyleSheet, Text, View } from 'react-native'
// eslint-disable-next-line import/no-unresolved
import GlobalKeyEvent from 'react-native-global-keyevent'
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
flex: 1,
justifyContent: 'center',
alignContent: 'center',
},
title: {
fontSize: 20,
textAlign: 'center',
marginBottom: 16,
},
text: { textAlign: 'center' },
})
export default function App() {
const [upEvent, setUpEvent] = useState(null)
useEffect(() => {
const up = GlobalKeyEvent.addKeyUpListener((evt) => setUpEvent(evt))
return () => up.remove()
})
return (
<View style={styles.container}>
<Text style={styles.title}>
Listening key up...
</Text>
{upEvent && (
<>
<Text style={styles.text}>
Key Code:
{' '}
{upEvent.keyCode}
</Text>
<Text style={styles.text}>
Pressed Key:
{' '}
{upEvent.pressedKey}
</Text>
<Text style={styles.text}>
Shift:
{' '}
{upEvent.flags?.shift ? 'YES' : 'NO'}
</Text>
<Text style={styles.text}>
Alt:
{' '}
{upEvent.flags?.alt ? 'YES' : 'NO'}
</Text>
<Text style={styles.text}>
Control:
{' '}
{upEvent.flags?.control ? 'YES' : 'NO'}
</Text>
<Text style={styles.text}>
Meta:
{' '}
{upEvent.flags?.meta ? 'YES' : 'NO'}
</Text>
<Text style={styles.text}>
Fn:
{' '}
{upEvent.flags?.fn ? 'YES' : 'NO'}
</Text>
<Text style={styles.text}>
Caps Lock:
{' '}
{upEvent.flags?.capsLock ? 'YES' : 'NO'}
</Text>
<Text style={styles.text}>
Numeric Pad:
{' '}
{upEvent.flags?.numericPad ? 'YES' : 'NO'}
</Text>
</>
)}
</View>
)
}