hammerspoon remap control key: sends esc when pressed alone, send control when pressed with other keys - macos-sierra

This is a extremely useful remap in my opinion, since you almost never type control alone, why not remap it to esc?
Since karabiner is gone I've been trying to restore my favourite feature using hammerspoon, I think this can be achieved but I just can't get it to work, does anyone know how to do this properly?

-- Sends "escape" if "caps lock" is held for less than .2 seconds, and no other keys are pressed.
local send_escape = false
local last_mods = {}
local control_key_timer = hs.timer.delayed.new(0.2, function()
send_escape = false
end)
hs.eventtap.new({hs.eventtap.event.types.flagsChanged}, function(evt)
local new_mods = evt:getFlags()
if last_mods["ctrl"] == new_mods["ctrl"] then
return false
end
if not last_mods["ctrl"] then
last_mods = new_mods
send_escape = true
control_key_timer:start()
else
if send_escape then
hs.eventtap.keyStroke({}, "escape")
end
last_mods = new_mods
control_key_timer:stop()
end
return false
end):start()
hs.eventtap.new({hs.eventtap.event.types.keyDown}, function(evt)
send_escape = false
return false
end):start()

Related

After updating neovim to 0.81 and all plugins to latest release, autocmd to highlight words on cursor hold is not working on certain languages

I have an auto command highlight words on cursor hold and this autocmd gets attached to buffer when the LSP server has the capability of documentFormattingProvider.
After updating neovim to 0.81 and all the plugins and language servers. The behaviour of this autocmd is buggy.
on svelte files, it does not work and actually outputs error: method textDocument/documentHighlight is not supported by any of the servers registered for the current buffer (lsp:svelte)
on python, no highlighting, no errors, but running lua vim.lsp.buf.document_highlight() on cmd line while cursor on repetitive word, it does highlight (lsp:pyright,black)
on go, it is working! (lsp:gopls)
on typescript files, it is working (lsp:tsserver)
on dart it is working (lsp:dartls)
Here is my dotfiles
local function lsp_highlight_document(client)
-- Set autocommands conditional on server_capabilities
if client.server_capabilities.documentFormattingProvider then
vim.api.nvim_exec(
[[
augroup lsp_document_highlight
autocmd! * <buffer>
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]],
false
)
end
end
I also tried (also not working):
local function lsp_highlight_document(client)
-- Set autocommands conditional on server_capabilities
if client.server_capabilities.documentFormattingProvider then
vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
vim.api.nvim_clear_autocmds({ buffer = bufnr, group = "lsp_document_highlight" })
vim.api.nvim_create_autocmd("CursorHold", {
callback = vim.lsp.buf.document_highlight,
buffer = bufnr,
group = "lsp_document_highlight",
desc = "Document Highlight",
})
vim.api.nvim_create_autocmd("CursorMoved", {
callback = vim.lsp.buf.clear_references,
buffer = bufnr,
group = "lsp_document_highlight",
desc = "Clear All the References",
})
end
end
Both of these functions gets called here
options.on_attach = function(client, bufnr)
if client.name == "tsserver" then
client.server_capabilities.documentFormattingProvider = true
end
if client.name == "sumneko_lua" then
client.server_capabilities.documentFormattingProvider = false
end
lsp_highlight_document(client)
lsp_keymaps(bufnr)
end
local capabilities = vim.lsp.protocol.make_client_capabilities()
local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
if not status_ok then
return
end
options.capabilities = cmp_nvim_lsp.default_capabilities(capabilities)
return options
Prior to this update, it was working fine in every language. Not sure what is missing.
Here is my config, which works for pyright, pylsp, lua-language-server etc.:
local api = vim.api
local lsp = vim.lsp
if client.server_capabilities.documentHighlightProvider then
vim.cmd([[
hi! link LspReferenceRead Visual
hi! link LspReferenceText Visual
hi! link LspReferenceWrite Visual
]])
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
api.nvim_create_autocmd("CursorHold" , {
group = gid,
buffer = bufnr,
callback = function ()
lsp.buf.document_highlight()
end
})
api.nvim_create_autocmd("CursorMoved" , {
group = gid,
buffer = bufnr,
callback = function ()
lsp.buf.clear_references()
end
})
end
Works well on nvim 0.8.1. Try it to see if it works. If it does not work, I think there is something wrong with your config, you need to dig deeper to find why.

Why is my Luau code not hiding the GUIs that I tried to hide?

My code is for hiding some GUIs that I don't want to show. (Note that this is Luau, I can't post to DevForums because I am not a member)
This is what I want to hide:
Link here
The code I used was:
local Dialog = false
local Confirm = false
local TalkTo = ""
local ConfirmGUI = script.Parent.Parent.Parent.Parent.ConfirmGUI.ScreenGui -- Avoiding waste of time writing the full directory and having to fail because it's in PlayerGUI
ConfirmGUI.TextButton.Visible = false
ConfirmGUI.TextButton2.Visible = false
ConfirmGUI.TextLabel.Visible = false
ConfirmGUI.TextTitle.Visible = false
The error I keep getting in Developer Console is:
09:04:06.668 ConfirmGUI is not a valid member of PlayerGui "Players.metoplayllol.PlayerGui" - Client - LocalScript:6
09:04:06.668 Stack Begin - Studio
09:04:06.669 Script 'Players.metoplayllol.PlayerGui.DialogGUI.ScreenGui.TextLabel.LocalScript', Line 6 - Studio - LocalScript:6
09:04:06.669 Stack End - Studio
I used a title you can't see because it ruins the fun of the experience.
Just use this code
ConfirmGUI.TextButton.Visible = false
ConfirmGUI.TextButton2.Visible = false
ConfirmGUI.TextLabel.Visible = false
ConfirmGUI.TextTitle.Visible = false
Try using:
script.Parent...Parent:WaitForChild('ConfirmGUI').ScreenGUI, or flip ScreenGUI and ConfurmGUI

BodyPosition not changing?

I've been sitting at my laptop for about an hour trying to figure out what's going on. I did this exact same thing yesterday and it worked. Please help.
Explaining the program:
The program takes the object that the mouse is pointing at, if you click the object gravitates toward the mouse.
local player = game.Players.LocalPlayer
local runservice = game:GetService("RunService")
local character = player.Character
local humanoid = character.Humanoid
local camera = workspace.Camera
local mouse = player:GetMouse()
local mousepos = mouse.hit.p
local grabbed = false
local function grabbedobj(obj) --this is the thing i need help on
local bodypos = obj.BodyPosition.Position
local pos = obj.Position
obj.Anchored = false
mouse.Button1Down:Connect(function()
grabbed = true
end)
mouse.Button1Up:Connect(function()
grabbed = false
end)
if grabbed == true then
print(obj.BodyPosition.Position)
bodypos = Vector3.new(mousepos.X, mousepos.Y, mousepos.Z) --really important
end
if grabbed == false then
bodypos = Vector3.new(pos.X, -25, pos.Z)
pos = Vector3.new(bodypos.X, pos.Y, bodypos.Z)
end
end
local function setup()
mousepos = mouse.hit.p
if mouse.Target ~= nil and mouse.Target.Parent == game.Workspace.IntObj then
grabbedobj(mouse.Target) --takes object that the mouse is pointing at
end
end
while wait(.1) do
setup()
end
Lets shuffle the code a little bit so it does what I think you want to do. You might have mixed up some things while trying to debug this. So here:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local grabbed = false
local obj
mouse.Button1Down:Connect(function()
if mouse.Target ~= nil and mouse.Target.Parent == game.Workspace.IntObj then
obj = mouse.Target
obj.Anchored = false
grabbed = true
end
end)
mouse.Button1Up:Connect(function()
if (grabbed) then
grabbed = false--BodyPosition
obj.BodyPosition.Position = Vector3.new(obj.Position.X, 0.1, obj.Position.Z)
obj.Anchored = true
end
end)
local function move()
if (grabbed) then
local mousepos = mouse.hit.p
obj.BodyPosition.Position = Vector3.new(mousepos.X, mousepos.Y, mousepos.Z)
print(obj.BodyPosition.Position)
end
end
while wait(.1) do
move()
end
When you click the mouse it checks if you click your part that is in IntObj. It will retain a reference to that part and then moves it with the mouse. When you release the button it will drop it at its location.
So this LocalScript should work but it has an issue updating the BodyPosition as you said in the title. The reason for that is that you can only update server parts from your client if you give the client permission from the server for it. You could write a remote function on the server and say:
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(plr)
Workspace.IntObj.Part:SetNetworkOwner(plr)
end
If you call this from your local script's initialization, it will work. Note, that your part cannot be anchored for that.
Another way would be to just let the server do the updating. So instead of setting the
obj.BodyPosition.Position on the client you would call the remote function like this:
game.ReplicatedStorage.RemoteFunction:InvokeServer(Vector3.new(mousepos.X, mousepos.Y, mousepos.Z))
and then on the server you set the position:
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(plr, bodyPos)
script.Parent.BodyPosition.Position = bodyPos
end
In that case, if you anchor/unanchor the part, do that on the server as well. Otherwise you'll get weird results.

Outlook form VBScript for controls

I've created an Outlook form with several bound controls. I would like one of the check boxes when checked to make two text areas and their labels visible, then not be visible if the check box is unchecked. The controls that I want to make visible have the initial state of not-visible. I'm stuck on the VBScript syntax. I've been using Sue Mosher's Outlook programming book, but I'm a newby and I'm not getting it. I'd appreciate any help with this. I'm using Outlook 2010 on a Windows 7 machine. Thanks!
Here's my code:
Sub Item_PropertyChange(byVal Name)
Set objInsp = Item.GetInspector
Set objPage = objInsp.ModifiedFormPages("Message")
Set ckWGC = objPage.Controls("ckWGC")
Set lblState = objPage.Controls("lblState")
Set WGCState = objPage.Controls("WGCState")
Set lblCountry = objPage.Controls("lblCountry")
Set WGCCountry = objPage.Controls("WGCCountry")
If ckWGC.Value = True Then
lblState.Visible = True
WGCState.Visible = True
lblCountry.Visible = True
WGCCountry.Visible = True
Else
lblState.Visible = False
WGCState.Visible = False
lblCountry.Visible = False
WGCCountry.Visible = False
End If
End Sub
You would want to handle the CheckBox.Change event to capture when the user has checked or unchecked it.
Private Sub CheckBox1_Change()
End Sub

Word Form - using VBA to enable textbox on checkbox click

I have the following VBA code to enable a textbox everytime a checkbox is clicked.
Private Sub CheckName1_Click()
If CheckName1.Value = True Then
TextName1.Enabled = False
TextName1.SpecialEffect = fmSpecialEffectFlat
Else
TextName1.Enabled = True
TextName1.SpecialEffect = fmSpecialEffectSunken
End If
End Sub
The problem is my document will probably have 30 of these by the time I am done (CheckName1, CheckName2, CheckRent1, CheckRent2, etc). I am already having trouble with Word lagging, so I'd like to create a subroutine that will call this sub instead of copy/pasting it again and again.
I haven't spent a lot of time with functions and the like- and even less with VBA. I just know the basics and they always make my head spin. So, this is what I have.
I just don't know how to pass the textbox parameter, or if I even have the checkbox parameter right.
And if this is close, do I still create a call for each checkbox?
Private Sub CheckName1_Click()
Call NA
End Sub
Private Sub NA(checkbox, textbox)
If checkbox.value = True Then
textbox.Enabled = False
textbox.SpecialEffect = fmSpecialEffectFlat
Else
textbox.Enabled = True
textbox.SpecialEffect = fmSpecialEffectSunken
End Sub
Thanks in advance for any help!
Loop on all controls
Based on this example: http://www.ozgrid.com/VBA/control-loop.htm
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "TextBox" Then
'DO STUFF HERE
End If
Next cCont