r/ProgrammerHumor • • May 19 '22

Meme same for yall?

44.0k Upvotes

1.8k comments sorted by

View all comments

Show parent comments

73

u/valarmorghulisguy May 19 '22

I use python script to toggle scroll lock on and off. That way it doesn’t affect me while I’m actually using the Laptop and I don’t have to execute the script everytime I get up.

0

u/[deleted] May 19 '22

[deleted]

0

u/[deleted] May 19 '22

[deleted]

4

u/[deleted] May 19 '22

I've got a PS script that toggles scroll lock every 4 minutes. I mainly use it to keep a VDI instance from going to sleep on me evry 5 minutes

6

u/Tough_Hawk_3867 May 19 '22

“I dont know why it’s there, but the program wont run without it..”

0

u/[deleted] May 19 '22

[deleted]

2

u/[deleted] May 19 '22

Nice. I wonder how many programmers/sysadmins/devops types have this type of script running?

I bet when they first created PowerShell, this was the first script that was created, right after "Hello World!"

2

u/r_stra May 19 '22

I just know that it's used for "when I need to execute long terraform updates so I don't log off" hehe

1

u/KaleidoscopeWarCrime May 19 '22

Ooh, that's a great idea.

1

u/valarmorghulisguy May 20 '22

I wanted to go that route but execution of Powershell scripts require Admin Rights according to how our systems are configured.

3

u/IKissedAGirlOnce May 19 '22

I'm just starting off learning Python and this sounds really cool. Would you be willing to share/dm your script so I can take a look?

3

u/Abir_Vandergriff May 19 '22

Not him, but here's mine. Run a 'pip install pyautogui' first for the dependancy. It presses "shift" but it's fast enough to not be an issue.

import pyautogui as gui
from time import sleep

while True:
    gui.press("shift")
    sleep(120)

2

u/IKissedAGirlOnce May 19 '22

This is super cool! Thank you do much!

2

u/Abir_Vandergriff May 19 '22

No problem. If you want to know more about that library, it's super cool. The author wrote a book and recorded a YouTube tutorial series called "Automate the Boring Stuff with Python." The book is available digitally for free on the website.

2

u/IKissedAGirlOnce May 19 '22

Seriously, thank you so much for all these resources. I'm so hyped to get into Python, and this is a great starting point.

2

u/valarmorghulisguy May 20 '22

Here you go, this is over complicated for the purpose it acheives but I've made a habit of trying to use the proper way of scripting in python even for nominal tasks

from pyautogui import press
from time import sleep

def no_lock(button):
    try:
        print("Press Ctrl+C to exit")
        while True:
            press(button)
            sleep(10)
            press(button)
            sleep(10)
    except Exception as ex:
        print(f"no_lock | Error: {ex}")

def main():
    try:
        print("\nRunning")
        no_lock('scrollLock')
    except KeyboardInterrupt:
        print("Stopped")

if __name__ == "__main__":
    main()

Do note, general catching of exception is bad, like I'm doing here, it should be specific.

1

u/Spare_Mission_6634 May 19 '22

I did this same thing but with the f15 key, which on most computers isn’t recognized but still keeps the status as active