Отслеживание клавиатуры

Отслеживаем нажатие клавиш на клавиатуре и совершаем действия

by Anatoly Kulikov

HTML

<div id="Keyboard-Window" class="Close">
  <form>
    <span>
      <img src="https://image.flaticon.com/icons/svg/116/116836.svg">
    </span>
    <input type="search" placeholder="Поиск">
  </form>
</div>

CSS

* {
  box-sizing: border-box;
}
body {
  display: block;
  width: 100%;
  height: 100vh;
  margin: 0;
  padding: 0;
  background: url(https://i.ytimg.com/vi/9fJEFi3ccwI/maxresdefault.jpg) center center no-repeat;
  background-size: cover;
}

#Keyboard-Window {
  width: 100%;
  height: 100%;
}
.Close {
  display: none;
}

.Open {
  display: flex;
  background: rgba(255,255,255,0.6);
}

form {
  display: flex;
  flex-wrap: nowrap;
  width: 400px;
  margin: auto;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: #9c9c9c 0px 0px 20px;
  background: #fff;
}
input[type=search] {
  display: block;
  width: 100%;
  max-width: 100%;
  border: none;
  outline: none;
  border-radius: 0px;
  padding: 14px;
  font-size: 24px;
  background: transparent;
}
span {
  display: block;
  width: 56px;
  background: #e8e8e8;
}
img {
  position: relative;
  top: 4px;
  display: block;
  width: 100%;
  height: auto;
  padding: 10px;
}

JavaScript

$(document).keydown(function(e){
      if(e.which === 91){
         $('#Keyboard-Window').toggleClass('Open');
      }
      return e;
});