title: How to control keyboard in Minecraft with Pynput
body: <p>I am trying to make a macro in Minecraft using pynput, but it seems that pynput does not press the correct buttons on the keyboard. I know this because when I ran (code snippet 1) while setting the controls of Hotbar slot 3 it showed as a weird character instead of a number. (see picture) Is there a way to make pynput press the correct buttons?  </p>
  
  <pre><code># Code snippet 1
  import time
  from pynput.keyboard import Controller
  
  time.sleep(7) # this is just so I have time to switch to minecraft before it activates
  
  board = Controller()
  board.press('2')
  time.sleep(.1)
  board.release('2')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kLVPB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kLVPB.png" alt="minecraft reads board.press(&#39;2&#39;) as soh\soh&quot;]&quot;soh"></a></p>
  
  <p>In place of <code>'2'</code> I have also tried <code>KeyCode(49)</code> and gotten the same result. It <em>is</em> properly recognised by the computer, as shown by <a href="http://keycode.info" rel="nofollow noreferrer">keycode.info</a> and notepad.<br>
  When I replaced <code>'2'</code> with <code>'e'</code> Minecraft recognised it as the same as <code>'2'</code>, and it even pressed the button, so I am extra confused now. </p>
  
  <h3>Extra notes:</h3>
  
  <ul>
  <li>For now I will just set the controls to what pynput gives minecraft to make my macro work, but I would prefer to be able to use the button(s) outside of the macro as well.  </li>
  <li>Pynput's click and scroll seem to work fine.  </li>
  <li>I am not using the mouse for my macro, but if you have knowledge about the mouse there is a stackOverflow question about it here: <a href="https://stackoverflow.com/questions/50712139">How to control the mouse in Minecraft using Python?</a>  </li>
  <li>For anyone wondering, I am making this macro to empty water buckets quickly after I have used them to remove an area of water in the ocean</li>
  </ul>