How to freak out someone

james.lu.75491856 -4 Tallied Votes 389 Views Share

THIS IS DANGEROOUS CODE, if it fails, it may prevent yu frome editing it.
also, you can use the functions to do crazy stuff. Look at this refrence and change the 0x12 to what you want.
(This one hold alt, so typing r will actibvate the menu that starts with 'r')

import os
SendInput = ctypes.windll.user32.SendInput

# C struct redefinitions 
PUL = ctypes.POINTER(ctypes.c_ulong)
class KeyBdInput(ctypes.Structure):
    _fields_ = [("wVk", ctypes.c_ushort),
                ("wScan", ctypes.c_ushort),
                ("dwFlags", ctypes.c_ulong),
                ("time", ctypes.c_ulong),
                ("dwExtraInfo", PUL)]

class HardwareInput(ctypes.Structure):
    _fields_ = [("uMsg", ctypes.c_ulong),
                ("wParamL", ctypes.c_short),
                ("wParamH", ctypes.c_ushort)]

class MouseInput(ctypes.Structure):
    _fields_ = [("dx", ctypes.c_long),
                ("dy", ctypes.c_long),
                ("mouseData", ctypes.c_ulong),
                ("dwFlags", ctypes.c_ulong),
                ("time",ctypes.c_ulong),
                ("dwExtraInfo", PUL)]

class Input_I(ctypes.Union):
    _fields_ = [("ki", KeyBdInput),
                 ("mi", MouseInput),
                 ("hi", HardwareInput)]

class Input(ctypes.Structure):
    _fields_ = [("type", ctypes.c_ulong),
                ("ii", Input_I)]

# Actuals Functions

def HoldKey(hexKeyCode):

    extra = ctypes.c_ulong(0)
    ii_ = Input_I()
    ii_.ki = KeyBdInput( hexKeyCode, 0x48, 0, 0, ctypes.pointer(extra) )
    x = Input( ctypes.c_ulong(1), ii_ )
    ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))

def ReleaseKey(hexKeyCode):

    extra = ctypes.c_ulong(0)
    ii_ = Input_I()
    ii_.ki = KeyBdInput( hexKeyCode, 0x48, 0x0002, 0, ctypes.pointer(extra) )
    x = Input( ctypes.c_ulong(1), ii_ )
    ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
HoldKey(0x12)

Dani AI

Generated

This is a bad idea in practice. As already warned, injecting low‑level keyboard events and then leaving a key held can make a machine hard to use: menus open, typing becomes unusable and you may lose control of editors. The first snippet here also never imports ctypes, so it will error immediately — double‑check imports and helper functions before running anything that talks to SendInput.

Two practical points that keep coming up in the thread: the difference between a tap and a hold, and how to test safely. The later posts reference a PressKey helper while the top snippet shows HoldKey/ReleaseKey helpers; make sure you have a release path (for example a finally that calls ReleaseKey) so a crashed script does not leave a modifier stuck. Test automation code inside a disposable environment — a VM, a throwaway account, or an isolated test machine — not on your primary workstation. Consider higher‑level automation libraries that include fail‑safes (they are less likely to leave the system unusable).

If something goes wrong, use the secure attention sequence to get out: press Ctrl+Alt+Delete and use Task Manager to kill the offending process (the SAS cannot be faked by injected input). If that is not possible, try unplugging an external keyboard, using the on‑screen keyboard, or remotely terminating the process from another machine. These recovery steps are worth planning before running any script that injects input.

Finally, a short ethics note. Pranks that take control of someone else’s computer are a quick way to lose trust and can violate workplace rules. The downvotes from and reflect that. If the goal is learning, focus on safe automation, clear undo behavior, and explicit consent.

james.lu.75491856 0 Junior Poster

0x15 makes you type japenese

james.lu.75491856 0 Junior Poster

tomap={' ':'0x20','1': '0x31', '0': '0x30', '3': '0x33', '2': '0x32', '5': '0x35', '4': '0x34', '7': '0x37', '6': '0x36', '9': '0x39', '8': '0x38', 'A': '0x41', 'C': '0x43', 'B': '0x42', 'E': '0x45', 'D': '0x44', 'G': '0x47', 'F': '0x46', 'I': '0x49', 'H': '0x48', 'K': '0x4B', 'J': '0x4A', 'M': '0x4D', 'L': '0x4C', 'O': '0x4F', 'N': '0x4E', 'Q': '0x51', 'P': '0x50', 'S': '0x53', 'R': '0x52', 'U': '0x55', 'T': '0x54', 'W': '0x57', 'V': '0x56', 'Y': '0x59', 'X': '0x58', 'Z': '0x5A'}

import time
print "go into a text editor in 5 secs"
time.sleep(5)
for i in 'YOU ARE GOOD':
    PressKey(int(tomap[i],0))
time.sleep(.5)
for i in range(4):
    PressKey(0x08) #backspace
for i in 'GREAT':
    PressKey(int(tomap[i],0))

The ghost program.

james.lu.75491856 0 Junior Poster

0x15 makes you type japenese
I was wrong, it doesn't work.

Nils_1 0 Newbie Poster

You get a downvote just because you enjoy to freak out people.

sneekula 969 Nearly a Posting Maven

This code snippet is pretty stupid.
If I could down vote it from my iPad, I would!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.