0

For my program I need to start by having a spacebar input. When spacebar is pressed it turns into a numeric value. It will turn into a counter.

  • Welcome to SO! What exactly have you tried so far? We're much more here to help with specific questions of the form "I tried X, but it did not do what I expect and instead resulted in an error!" accompanied by a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – ti7 Oct 25 '22 at 01:04
  • What turns into a numeric value? The spacebar? – Samwise Oct 25 '22 at 01:05
  • @Samwise I can only assume that what is meant is that there will be a counter variable in the program, which will count the number of times the space bar is pressed. – Karl Knechtel Oct 25 '22 at 01:11

1 Answers1

0

I think this is what you mean:

import keyboard

counter = 0

while (1):
  keyboard.wait('space')
  counter += 1
  print('Counter:', counter)

modified from this answer.

L8R
  • 401
  • 5
  • 21