Skip to content

Conversation

@quangd42
Copy link

This allows Hammerspoon users to update the escape tap time in their config without meddling with the code of the Spoon itself

Copy link
Owner

@jasonrudolph jasonrudolph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this thoughtful pull request, and for taking the time to update the docs as well. When you have a moment, please see the question below.

init.lua Outdated
Comment on lines 24 to 23
self.controlKeyTimer = hs.timer.delayed.new(CANCEL_DELAY_SECONDS, function()
self.controlKeyTimer = hs.timer.delayed.new(self.tapTime, function()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 @quangd42: I tried testing this locally, but it seems to always use the default value of 150 ms, even if I follow the updated instructions in the README.

I have a feeling that this is due to hs.timer.delayed.new(self.tapTime, ...) being called in obj:init() at initialization time, and therefore any changes made to self.tapTime after object initialization have no effect on the timer. That's my best guess at least.

If you're able to get this pull request working as desired and you can describe how to verify the new behavior, I'm happy to take another look.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at this. To be honest I was not so sure how to verify the delay amount of the controlKeyTimer, as hs.timer does keep an internal state for the delay amount.

So I ended up moving the initialization of the timer to the start method so it's clear what value of CANCEL_DELAY is being passed to the timer, and it only happens once. Hopefully this is straightforward enough to eliminate guess work.

Thanks!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Hi @quangd42 - I've checked out the latest updates. They do look like they should work, but I still haven't been able to definitively verify that they work. Before accepting any changes, it's important to me that I'm able to verify the new behavior. Can you describe a process for manually testing this behavior to verify that it's working as you expect?

Copy link
Author

@quangd42 quangd42 May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jasonrudolph - In my latest commit you can find a few commented lines of code that will log elapsed time since the timer starts until either 'escape' is sent or the timer is canceled, using https://www.hammerspoon.org/docs/hs.timer.html#absoluteTime. I pushed the code as comments so that the PR can be merged as is and avoid the extra overhead.

Here are the steps:

  1. Uncomment the logging code.
  2. In init.lua, call start(200) on the module. Open hammerspoon console and reload config.
  3. Hold 'control' key. Expect to see 'timer canceled after {time} ms' in the console, where time is approximately 200.
  4. Press and quickly release 'control' key. Expect to see 'escape sent after {time} ms' in the console, where time is less than 200.

Let me know if that will work.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants