Skip to content

Instantly share code, notes, and snippets.

@0mj
Last active May 16, 2025 18:55
Show Gist options
  • Select an option

  • Save 0mj/a8d881c4c82a61bd0af8fb5d4074b88c to your computer and use it in GitHub Desktop.

Select an option

Save 0mj/a8d881c4c82a61bd0af8fb5d4074b88c to your computer and use it in GitHub Desktop.
Ruby script calls a Powershell script, which presses scroll lock key.
System('powershell', '-Command', '(New-Object -ComObject WScript.Shell).SendKeys("{SCROLLLOCK}")')
  • system() - This is a Ruby method that executes external commands on your operating system. It's like asking Ruby to step aside and let your computer's command line take over temporarily.
  • 'powershell' - This is the first argument, telling Ruby to run PowerShell, which is a command-line tool and scripting language on Windows systems.
  • '-Command' - This is the second argument, telling PowerShell to execute the following command.
  • The third argument is a PowerShell script enclosed in quotes: '(New-Object -ComObject WScript.Shell) creates a Windows Script Host Shell object, which can interact with Windows. .SendKeys("{SCROLLLOCK}")' tells this object to simulate pressing the Scroll Lock key.

Tip

Keep-alive scripts: Remote management: Gaming automation: Kiosk setups: Scroll Lock light control:

many organizations have policies against keyboard automation for security reasons, and some applications may detect and block automated inputs. Using such scripts should be done thoughtfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment