Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
react-native-hw-keyboard-event
Advanced tools
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 222 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.