1

I have a simple question for you, which I dont seem to find an answer too.

Im trying to make an AutoClicker of sort, to press a keyboard key continuesly. Here is my code:

while True:
    keyboard.wait(k) ## k = k to press
    mouse.click('left') ## the click
    time.sleep(0.5) ## delay

This code works fine, but I have a problem, if I press an another key with 'K' it doesnt work, and I want to make it click anytime there is the 'K' key pressed, no matter with what other key it is pressed with. Like if I press K + B + C I want the autoclicker to still activate because K is pressed. I have tried searching for a solution to this problem but I havent found anything.

Thanks for any help!

  • 1
    Try removing the ```time.sleep(0.5)``` from your code. – glory9211 Jan 05 '22 at 15:02
  • Any key or are you pressing multiple non-modifier keys to which your keyboard is ignoring additional key presses? i.e [Why can't I press more than three buttons on my keyboard while playing a video game?](https://www.quora.com/Why-cant-I-press-more-than-three-buttons-on-my-keyboard-while-playing-a-video-game) – Sayse Jan 05 '22 at 15:02
  • @Sayse the problem is, I want the autoclicker to activate when pressing "K", but also activate if im pressing K and other buttons like. If i press K + B + C, I want the autoclicker to still activate, because im pressing K. – Super Boxes Jan 05 '22 at 15:07
  • Try pressing K+B+C, all at the same time into this comment section, you'll probably notice that your keyboard doesnt support this input – Sayse Jan 05 '22 at 15:08
  • @Sayse Well yes, but If I go to any keyboard website, the keys that are pressed are still detected. – Super Boxes Jan 05 '22 at 15:10
  • I do not use the `keyboard` module, but after a quick look on its documentation, I think that `keyboard.on_press_key` could be relevant for your use case. – Serge Ballesta Jan 05 '22 at 15:23

1 Answers1

2

It looks like the below question solves your issue. I tried it and it works for the combination of K + B + C key presses. You need to install keyboard module.

How to detect key presses?

Code that I tried (copied from the question above with minor updates)

import time
import keyboard  # using module keyboard
while True:  # making a loop
    try:  # used try so that if user pressed other than the given key error will not be shown
        if keyboard.is_pressed('k'):  # if key 'q' is pressed 
            print('You Pressed k Key!')
            #break  # finishing the loop
    except:
        break  # if user pressed a key other than the given key the loop will break
    time.sleep(0.1)

Note: Without the sleep of 0.1, the key press event is printed multiple times.

Manjunath K Mayya
  • 1,078
  • 1
  • 11
  • 20