Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Hooking keyboard input to play Snake in Notepad.exe (2020) (kylehalladay.com)
88 points by goranmoomin on April 8, 2021 | hide | past | favorite | 16 comments


Someone also uses notepad as a debug console [1]. There is even a Rust crate for that [2].

[1] https://www.reddit.com/r/programming/comments/gnazif/ray_tra... (I've first seen this from Steve Klabnik's tweet https://twitter.com/steveklabnik/status/1263190719721766918)

[2] https://crates.io/crates/notepad_logger


Could have probably gotten the keyboard input with https://docs.microsoft.com/en-us/windows/win32/api/winuser/n... instead of the hooks.


Excellent write-up.

I think the first place I encountered this sort of thing in notepad was http://thesiteformerlyknownas.zachtronicsindustries.com/note...


I did socket hooking via DLL injection for a company i worked for. I was somewhat amazed that it was allowed, and I'm amazed it still is.


I've mentioned it here before. I have a "cd" replacement tool for Windows. It works by writing a separate thread to cmd.exe's process and remotely running it to do things in cmd's process (change the current directory, update a few enviornment variables cmd.exe uses behind the scenes). I am flabbergasted that it works, and it still works after all of these years.


Is the code available somewhere? I would be interested to read it


If you really want to see it, I put the core of it here:

https://pastebin.com/v92Aesty

ExecuteRemoteThread() does what it's name says, copying RemoteThread to cmd.exe, and running it. The rest of the code is about getting pointers to a few WinAPIs that are used in a safe way, and dancing around not having a CRT that can be sanely used inside of cmd.exe.


Thanks!


I've also done some socket hooking work in C/C++. Any idea if it's feasible to do with Go?


It seems a lot of people have the same idea of implementing Snake where it has no business being

https://twitter.com/neilsardesai/status/1379185826920300545?...


And ... it's in Sub Rosa, the obscure cult-like game stuck in the 80s universe of shady business dealings: https://twitter.com/crypticsea/status/1377433014674714624

For those of you who don't know it, it's a rather obscure and in some ways delightfully refreshing game, albeit populated by unsavory players worth of the Mos Eisley cantina quote taken at its face value. It's based on two things, physics-based movement and the prisoner's dilemma split three-ways.

"Deal-making, deal-breaking, and the occasional high-speed car chase." And of course, having to walk up to a computer and type MS-DOS commands to play snake. The developer plans to make the game's computer a "full 6502 or Z80 emulation so players can write their own games."


https://github.com/emacs-mirror/emacs/blob/master/lisp/play/...

1997 is actually later than I would've thought.


This is great. I didn't expect `M-x snake` to be available out of the box like that :)


try dunnet, tetris, hanoi, blackbox, bubbles, pong, gomoku,...


Pretty cool. The next step is, of course, porting Doom to it :)


"Your scientists were so preoccupied with whether or not they could, they didn’t stop to think if they should."




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: