I made a keydown/keyup script that fires a search bar when pressing cmd+k. The issue I'm facing is that the browser doesn't recognize when I'm holding the cmd key. For the "K" key, there's seem to be an autorepeat by default thus allowing me to simply hold "K" and pressing Cmd to show the search bar.
I want the reverse. How can I hold Cmd and press another key (K) to fire my search bar?
class Dashboard extends Component {
state = {
showSearch: "",
HideShowSearch: false,
};
HideShowSearch = (e) => {
var map = {};
let HideShowSearch = this.state.HideShowSearch;
var self = this;
onkeydown = function (e) {
e = e;
map[e.keyCode] = e.type === "keydown";
// Cmd + K
if (map[75] && map[91]) {
self.setState(() => ({ HideShowSearch: !HideShowSearch }));
}
};
};
render() {
this.HideShowSearch();
return (
<div>
<div className="row align-items-center">
<div className="container col-12">
{this.state.HideShowSearch ? (
<Searchbox
onChange={this.onTextChanged}
item={this.state.items}
onKeyPress={this.handleKeyPress}
text={this.state.text}
suggestions={this.renderSuggestions()}
onKeyDown={this.onKeyDown}
/>
) : null}
</div>
</div>
</div>
);
}