Showing posts with label hacks. Show all posts
Showing posts with label hacks. Show all posts

Sunday, February 18, 2024

Disable Windows double-finger-click

My new work laptop did not have dedicated buttons, and by default Windows set it up so that a two-finger tap or click on the touchpad would trigger a right-button click. I turned on the non-default setting that lets me click in the lower-right part of the touchpad to get a right button click, and turned off the two-finger tap options. There is no way to turn off the option for generating a right-button click with a two-finger click. 

This might seem quite innocent, but I kept on getting fake right-button clicks instead of left-button clicks when clicking the touchpad. I changed the registry settings to make the right-click area really small. It didn't solve the problem. Finally, I figured out what was going on: I click the touchpad with the side of my right thumb. This seems to result in the touchpad occasionally registering the tip and joint of my right thumb as separate contacts. The bad right-clicks were driving me crazy. I searched through registry and Windows .sys and .dll files for some hidden option to turn off the two-finger click for right-button clicks, finding nothing. Nothing. I tried to install some older proprietary touchpad driver, but none of them worked.

Finally, it was time to write some code to disable the bad right clicks. After a bunch of hiccups (I almost never write code that interacts with the Windows API), and a Python-based prototype, I wrote a little C program. Just set disable-two-finger-right-click.exe to run as Administrator in Task Scheduler on login, and it takes care of it. The code uses rawinput to get the touchpad HID report, uses the HidP-* functions to parse it, and registers a low level mouse hook to remap the bad right clicks to left clicks based on some heuristics (mainly based around how long ago there was a two-finger click before the right click, while ignoring the official right-click area of the touchpad). 

So many hours that would have been saved if Microsoft just added an extra option.

Monday, July 30, 2018

Setting a very low security expiry date on a pdf

Sometimes one wants someone (even oneself) to have a PDF that becomes unviewable past a certain date, but the expiry isn't meant to be secure--perhaps one is sharing a manuscript between friends but one doesn't want one's friend to access an out of date version.

Here's a simple way that works with Adobe's Acrobat Reader and maybe some other readers (but not all others--e.g., Sumatra ignores the expiry entirely), based on combining two ideas I found online. It only works on PDFs that haven't already been compressed or encrypted. Load the PDF into a text editor. Find the code /Type /Catalog. Insert this bit of code right after that code, changing the date to match your needs:
/Type /Catalog
/Names <<
    /JavaScript <<
      /Names [
        (EmbeddedJS)
        <<
          /S /JavaScript
          /JS (
var rightNow = new Date();
var endDate = new Date(2018, 7, 10); // expiry date: year, month (0=Jan, 11=Dec), day
if(rightNow.getTime() > endDate)
{
app.alert("This document has expired.");
this.closeDoc();
}
          )
        >>
      ]
    >>
  >>
Then load it into Acrobat Reader. Acrobat Reader should display it, but when you exit it will ask to save the file. Agree, as this will hide the above code and make it no longer easy to edit.