Saturday, December 4, 2021

RewindNs

 While taking online classes via Zoom, sometimes the slides go really fast and I cannot finish writing. In such times I wish I had a magic button to go back a few seconds and hold it right there until I complete noting down the slide. I know there's always the option to record it all (OBS works fine) and go to whatever time in the video and take notes from there but having something akin to Nvidia instant replay would be neat. That's the concept behind this program.

I chose Visual Basic 6 (or the way I call it - vb6) to code it up because it had been some time that I had not used it. It used to be my go-to language/IDE for making anything and everything before 5 years or so when I made the switch to C# and the rest. I remember the IDE being super snappy, the compiled file size (12-20 KB for a normal windows form/standard EXE application) super small by today's oversized standards. It was such a breeze to get things done without worrying about classes, objects and all that convenience. And doing things you were not supposed to be doing in vb6 (multithreading, executing shellcode/assembly, calling undocumented win32 API, etc.) and getting them to work (after shooting yourself in the foot a hundred times of course) was such a treat. I guess I wanted to feel that again. I don't think there's yet been another language that has been able to occupy that sweet niche for me. PureBasic and Delphi/FreePascal Lazarus come somewhat close but they're a significant compromise.

Anyway, I started it yesterday (~6PM perhaps) and finished it today afternoon (~2PM). It turned out to be a bit more work than I had thought it would be - I guess my observation that one has to underestimate the effort it takes to complete a project to actually embark upon it is something that I will never learn from. It's done now and here I am writing this up at 8:10 PM. There's still a few nice-to-have features I'd like to add but this version works just fine for what this program is supposed to do.

Flowchart of the program
If you can't make the flowchart, in a nutshell, the program maintains an array of screen's memory DC (Device Context) - basically a screen capture - and it paints the first element of the array over and over in a loop over the screen when the user presses the 'J' key twice, until the user presses the 'L' key twice. The array's length is equal to the history timespan divided by the sampling interval; so if the history timespan is 5 seconds (meaning save a history of 5 seconds i.e. 5000 milliseconds) and the sampling interval is 100 milliseconds (meaning the screen capture is performed every 100 milliseconds), the array will have a size of 5000/100 = 50. This array is maintained so that only the most recent 50 captures are present at any given moment. This means the array is first filled normally up to the end, then the elements are pushed one position to the left each time a new capture is performed so that it can be placed at the last position. The captures in the array move from the oldest to the most recent left to right (start to end). Here's how it looks. You can right click on it to hide the window.

Here's the GitHub link for the project. Here's the download link.