from pynput.keyboard import Key, Controller import time import re def getnumbers(): """…
- User
from pynput.keyboard import Key, Controller import time import re
def get_numbers(): """ Collect numbers from user input, allowing input pasted at once. """ print("Enter the numbers to paste (separated by semicolons, commas, or newlines):") user_input = input() # Split input on semicolons, commas, and newlines numbers = re.split(r'[;\n,]+', user_input) # Strip whitespace and filter out empty strings numbers = [num.strip() for num in numbers if num.strip()] return numbers
def press_and_release(key, pause=0.005): """ Press and release a key with an optional pause. """ keyboard.press(key) keyboard.release(key) time.sleep(pause)
def paste_numbers(numbers): """ Paste numbers into GeoGebra (or similar application) using keyboard automation. """ total_numbers = len(numbers) print(f"Total numbers to paste: {total_numbers}")
# Provide time to switch to the target application print("Switch to the target application. Starting in 5 seconds...") time.sleep(5) # Make the first cell editable press_and_release(Key.f2) # Initialize counter count = 0 for number in numbers: # Type number directly keyboard.type(number) time.sleep(0.01) # Small pause to ensure typing is registered # Press Tab to move to next cell press_and_release(Key.tab) count += 1 if count % 3 == 0 and count != total_numbers: # Move to the next row if needed # Press Tab to move to the cell in the next row press_and_release(Key.tab) # Make the new cell editable press_and_release(Key.f2) time.sleep(0.01) # Final action after all numbers are pasted press_and_release(Key.space)def main(): numbers = get_numbers() paste_numbers(numbers)
if name == 'main': keyboard = Controller() main()
Before switching to Geo Zeb, pasting the numbers I need (18 )on the command line's not possible. i have these numbers, but it pastes just the first string. which are 3 numbers. then it starts the countdown. i want to be able to paste all 18. here is an example of how they are formatted. 61.14; -92.09; 2.13 -97.90; -84.31; 8.42 -16.76; 20.27; 7.18 487685.74; 4391200.78; 476.59 487776.73; 4391070.11; 482.81 487644.37; 4391070.47; 481.47
for more context, here's how i was doing on a different revision of the script. so be careful
Collect numbers from user input
print( "Enter the numbers to paste (semicolons and new lines separated):\n" "(Press Enter on an empty line to finish input)" ) numbers = [] while True: line = input() if not line: break numbers.extend([num.strip() for num in line.strip().split(';') if num.strip()]) total_numbers = len(numbers) print(f"Total numbers to paste: {total_numbers}") # Provide time to switch to Geo Zeb print("Switch to Geo Zeb. Starting in 5 seconds...") time.sleep(5) - Assistant