Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
react-native-hw-keyboard-event
Advanced tools
Event handler for hardware keyboard keystrokes
Weekly downloads
Readme
Run npm install react-native-hw-keyboard-event --save
Run yarn add react-native-hw-keyboard-event
pod install
inside your ios
folder.
Override dispatchKeyEvent
in your MainActivity.java
import android.view.KeyEvent; // IMPORTANT
import com.github.emilioicai.hwkeyboardevent.HWKeyboardEventModule; // IMPORTANT
public class MainActivity extends ReactActivity {
......
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
// Detects user pressing the enter key
if (event.getAction() == KeyEvent.ACTION_DOWN && !event.isShiftPressed()){
// Enter is pressed
HWKeyboardEventModule.getInstance().keyPressed("enter");
return true;
}
if (event.getAction() == KeyEvent.ACTION_DOWN && event.isShiftPressed()){
// Shift-Enter is pressed
HWKeyboardEventModule.getInstance().keyPressed("shift-enter");
return true;
}
}
return super.dispatchKeyEvent(event);
};
......
}
Add the keyCommands
method to your AppDelegate.m
file:
#import <RNHWKeyboardEvent.h> // IMPORTANT
@implementation AppDelegate
//....
RNHWKeyboardEvent *hwKeyEvent = nil;
- (NSMutableArray<UIKeyCommand *> *)keyCommands {
NSMutableArray *keys = [NSMutableArray new];
if (hwKeyEvent == nil) {
hwKeyEvent = [[RNHWKeyboardEvent alloc] init];
}
if ([hwKeyEvent isListening]) {
[keys addObject: [UIKeyCommand keyCommandWithInput:@"\r" modifierFlags:0 action:@selector(sendEnter:)]];
[keys addObject: [UIKeyCommand keyCommandWithInput:@"\r" modifierFlags:UIKeyModifierShift action:@selector(sendShiftEnter:)]];
}
return keys;
}
- (void)sendEnter:(UIKeyCommand *)sender {
// Detects user pressing the enter key
NSString *selected = sender.input;
[hwKeyEvent sendHWKeyEvent:@"enter"];
}
- (void)sendShiftEnter:(UIKeyCommand *)sender {
// Detects user pressing the shift-enter combination
NSString *selected = sender.input;
[hwKeyEvent sendHWKeyEvent:@"shift-enter"];
}
@end
Whenever you want to use it within React Native code now you can:
import HWKeyboardEvent from 'react-native-hw-keyboard-event';
...
componentDidMount() {
HWKeyboardEvent.onHWKeyPressed(this.handleHardwareEnterPress);
}
componentWillUnmount() {
HWKeyboardEvent.removeOnHWKeyPressed();
}
handleHardwareEnterPress = (keyEvent) => {
switch (keyEvent.pressedKey) {
case 'enter': this.handleSendMessage();
break;
case 'shift-enter': this.handleInsertTextToDraft('\n');
}
}
...
FAQs
Event handler for hardware keyboard keystrokes
The npm package react-native-hw-keyboard-event receives a total of 220 weekly downloads. As such, react-native-hw-keyboard-event popularity was classified as not popular.
We found that react-native-hw-keyboard-event demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.