Вопрос Помогите с кодом

Everage C++ Enjoyer
Пользователь
Статус
Оффлайн
Регистрация
5 Янв 2018
Сообщения
164
Реакции[?]
50
Поинты[?]
3K
Нужно сделать чтобы при повторном нажатии caps lock программа останавливалсь и при еще одном повторном нажатии запускалась заново
Я в пайтоне вообще не ебу че да как
Python:
import pyautogui as pygui
import time
import keyboard as key

x = 1007
num = 1007

while True:
    if key.is_pressed('9'):
        print('EXIT AND CLOSE PROGRAMM')
        break
    if key.is_pressed('capslock'):
        while x > 7:
            key.press_and_release("shift+enter")
            time.sleep(0.3)
            x = x - 7
            num = str(f"{x}-7")
            pygui.write(str(num))
            time.sleep(0.05)
            key.press_and_release('enter')
            time.sleep(0.05)
 
Начинающий
Статус
Оффлайн
Регистрация
21 Мар 2021
Сообщения
94
Реакции[?]
29
Поинты[?]
7K
Нажатие Caps Lock - вкл / выкл

Python:
import ctypes

# user32.dll, kernel32.dll (WinAPI)
user32 = ctypes.windll.user32
kernel32 = ctypes.windll.kernel32

# Глобальные и статичсике переменные
value = 1000
keycodes_dict = {str(key): key + 48 for key in range(10)}
keycodes_dict["-"] = 0xBD
keycodes_dict[" "] = 0x20


# Основной код
def press_and_release(key_codes: list[int, ...]) -> None:
    """WinAPI вызов нажатия и отпуска кливиатуры"""

    [user32.keybd_event(key_code, 0, 0, 0) for key_code in key_codes]   # Нажание
    [user32.keybd_event(key_code, 0, 2, 0) for key_code in key_codes]   # отпуск


def keyboard_write(key_codes: list[int, ...]) -> None:
    """Печать текста"""

    for key_code in key_codes:
        print(key_code)

        user32.keybd_event(key_code, 0, 0, 0)   # Нажание
        user32.keybd_event(key_code, 0, 2, 0)   # отпуск


while True:

    # 0x39 - 9 (https://narvell.nl/keys)
    if user32.GetKeyState(0x39) > 2:
        break

    # 0x14 - Caps Lock (https://narvell.nl/keys)
    if user32.GetKeyState(0x14):

        # 0xA0 - LShift, 0x0D - Enter
        press_and_release([0xA0, 0x0D])
        kernel32.Sleep(300)

        text_to_write = [keycodes_dict[char] for char in f"{value} - 7"]
        keyboard_write(text_to_write)

        value -= 7

        press_and_release([0x0D])
1675009596927.png
 
Последнее редактирование:
Everage C++ Enjoyer
Пользователь
Статус
Оффлайн
Регистрация
5 Янв 2018
Сообщения
164
Реакции[?]
50
Поинты[?]
3K
Нажатие Caps Lock - вкл / выкл

Python:
import ctypes

# user32.dll, kernel32.dll (WinAPI)
user32 = ctypes.windll.user32
kernel32 = ctypes.windll.kernel32

# Глобальные и статичсике переменные
value = 1000
keycodes_dict = {str(key): key + 48 for key in range(10)}
keycodes_dict["-"] = 0xBD
keycodes_dict[" "] = 0x20


# Основной код
def press_and_release(key_codes: list[int, ...]) -> None:
    """WinAPI вызов нажатия и отпуска кливиатуры"""

    [user32.keybd_event(key_code, 0, 0, 0) for key_code in key_codes]   # Нажание
    [user32.keybd_event(key_code, 0, 2, 0) for key_code in key_codes]   # отпуск


def keyboard_write(key_codes: list[int, ...]) -> None:
    """Печать текста"""

    for key_code in key_codes:
        print(key_code)

        user32.keybd_event(key_code, 0, 0, 0)   # Нажание
        user32.keybd_event(key_code, 0, 2, 0)   # отпуск


while True:

    # 0x39 - 9 (https://narvell.nl/keys)
    if user32.GetKeyState(0x39) > 2:
        break

    # 0x14 - Caps Lock (https://narvell.nl/keys)
    if user32.GetKeyState(0x14):

        # 0xA0 - LShift, 0x0D - Enter
        press_and_release([0xA0, 0x0D])
        kernel32.Sleep(300)

        text_to_write = [keycodes_dict[char] for char in f"{value} - 7"]
        keyboard_write(text_to_write)

        value -= 7

        press_and_release([0x0D])
Посмотреть вложение 236737
короче все круто работает но но.
то что я в примере скинул это скрипт для доты, он помимо того чтобы писать еще открывает чат и закрывает:
1675018368253.png
 
Начинающий
Статус
Оффлайн
Регистрация
21 Мар 2021
Сообщения
94
Реакции[?]
29
Поинты[?]
7K
короче все круто работает но но.
то что я в примере скинул это скрипт для доты, он помимо того чтобы писать еще открывает чат и закрывает:
Посмотреть вложение 236764
Так в коде, что я написал все закоменчено и понятно, просто сделай копипаст парочки вызовов ф-ий в нужные тебе местах и все будет отлично работать.
 
Everage C++ Enjoyer
Пользователь
Статус
Оффлайн
Регистрация
5 Янв 2018
Сообщения
164
Реакции[?]
50
Поинты[?]
3K
Так в коде, что я написал все закоменчено и понятно, просто сделай копипаст парочки вызовов ф-ий в нужные тебе местах и все будет отлично работать.
попробую но пайтон для меня как темный лес но думаю разберусь
 
Начинающий
Статус
Оффлайн
Регистрация
21 Мар 2021
Сообщения
94
Реакции[?]
29
Поинты[?]
7K
Начинающий
Статус
Оффлайн
Регистрация
30 Окт 2020
Сообщения
51
Реакции[?]
5
Поинты[?]
0
This code listens for a '9' key press and, if detected, will print a message and exit the program. When the caps lock key is pressed, the code enters a loop where it continuously performs the following actions until the value of x becomes less than 7:

  1. Press and release the 'shift + enter' key combination.
  2. Wait for 0.3 seconds.
  3. Subtract 7 from x and store the result in x.
  4. Convert x to a string and concatenate it with the string "-7" to form the string num.
  5. Write the value of num using the pyautogui library.
  6. Wait for 0.05 seconds.
  7. Press and release the 'enter' key.
  8. Wait for 0.05 seconds.
 
Сверху Снизу