![]() FOR BEGINNERS CONTINUED: An anonymous function is just a function without an identifier (name), instead they're objects and often behave kinda like variables (look this up, it's kinda hard to explain and not relevant here) FOR BEGINNERS: "function(event)" creates anonymous function containing the below code and passes it the keydown event as an object called "event" (Just makes the code neater, you could use a separate function if you want) Local pressTime, firstDown = 0, false -pressTime was the time the first press occurred which is set to 0, and firstDown indicates if the first press has occurred or notĮventtap.new(, function(event) Return condsSinceEpoch() - time < timeFrame -if the time passed from the first press to the second was less than the timeframe, then it was in time Return ke圜ode = key -return if ke圜ode is keyįunction inTime(time) -checks if the second press was in time Hs.alert("Pressed ` twice!") -the handler for the double pressįunction correctKe圜hecker(event) -keypress validator, checks if the keycode matches the key we're trying to detect ![]() print(keycodes.map) you can look up the certain keycode by accessing the map Key = 50 -the specific keycode we're detecting, in this case, 50 TimeFrame = 1 -this is the timeframe in which the second press should occur, in seconds anycodings_hammerspoon Note that the flags could be implemented anycodings_hammerspoon as booleans here, or as an internal anycodings_hammerspoon table holding keypresses so far which anycodings_hammerspoon you could check: local timer = require("hs.timer") Translated into code, this is what is anycodings_hammerspoon could look like (I'm not a Lua expert). If it wasn't the right key then reset the timer and first flag.If it was the second press and was in time, then execute our handler and reset timer and first flag.If it was the right key, check if it's the second press and if it was in time, if it wasn't in time or was not the second press then set the timer to the current time and first flag to true.When the event ( keyPress) happens, check if the key pressed was the correct key.Observe and watch keypresses with hs.eventtap, specifically hs.Start a timer from zero, and set a flag for the first press initially to false, which indicates the first press has not happened yet.Here's a basic summary of how anycodings_hammerspoon to accomplish this: You're going to have to implement this anycodings_hammerspoon yourself.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |