remap apostrophe to other keys using hammerspoon - hammerspoon

the problem is caused by library's bug and this had been fixed.
I'm using hammerspoon and I'm trying to remap Ctrl + ' to backtick(`) but I cannot.
the setting file init.lua is like below:
local function keyCode(key, modifiers)
modifiers = modifiers or {}
return function()
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), true):post()
hs.timer.usleep(100)
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), false):post()
end
end
local function remapKey(modifiers, key, keyCode)
hs.hotkey.bind(modifiers, key, keyCode, nil, keyCode)
end
remapKey({'ctrl'}, 'h', keyCode('delete')) // works
remapKey({'ctrl'}, "'", keyCode("`")) // does not work
error message is:
Invalid key: ' - this may mean that the key requested does not exist in your keymap (particularly if you switch keyboard layouts frequently)
it seems the problem is hs.keycodes.map does not include apostrophe (but it includes double-quote and backtick).
is it possible to remap apostrophe?

The point here is the keyboard layout (that Hammerspoon thinks your keyboard is in).
Do you actually have an apostrophe (`) key on your keyboard?
I mean, if you need to type something like shift+# to input the apostrophe, then you must tell so to newKeyEvent.
remapKey({'ctrl'}, "'", keyCode("#", {"shift"}))
Or, you could simply use hs.eventtap.keyStroke() in the keyCode() function if you don't want to bother with how to type a string using the keyboard:
local function keyCode(key, modifiers)
modifiers = modifiers or {}
return function()
hs.eventtap.keyStroke(modifiers, key)
end
end
As for hs.keycodes.map having the double quote instead of the single quote, it turned out to be a bug of Hammerspoon, so I've just filed a PR.

Related

VBSCRIPT REPLACE not removing spaces from Decrypted fields

Got quite a head-scratcher....
I'm using the VBScript function REPLACE to replace spaces in a decrypted field from a MSSQL DB with "/".
But the REPLACE function isn't "seeing" the spaces.
For example, if I run any one of the following, where the decrypted value of the field "ITF_U_ClientName_Denc" is "Johnny Carson":
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"),"Chr(160)","/")
REPLACE(CSTR(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"))," ","/")
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/",1,-1,1)
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc")," ","/",1,-1,0)
The returned value is "Johnny Carson" (space not replaced with /)
The issue seems to be exclusively with spaces, because when I run this:
REPLACE(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"),"a","/")
I get "Johnny C/rson".
Also, the issue seems to be exclusively with spaces in the decrypted value, because when I run this:
REPLACE("Johnny Carson"," ","/")
Of course, the returned value is "Johnny/Carson".
I have checked what is being written to the source of the page and it is simply "Johnny Carson" with no encoding or special characters.
I have also tried the SPLIT function to see if it would "see" the space, but it doesn't.
Finally, thanks to a helpful comment, I tried VBS REGEX searching for \s.
Set regExp = New RegExp
regExp.IgnoreCase = True
regExp.Global = True
regExp.Pattern = "\s" 'Add here every character you don't consider as special character
strProcessed = regExp.Replace(ITF_U_Ledger.Fields("ITF_U_ClientName_Denc"), "?")
Unfortunately, strProcessed retruns "Johnny Carson" (ie. spaces not detected/removed).
If I replace regExp.Pattern = "a", strProcessed returns "Johnny C?rson".
Many thanks for your help!!
As we found, the right character code is 160, and that did the trick:
replace(..., ChrW(160), "...")
This seems to be data specific and, additionally, as an alternative you can try to get same encoding of the source script (i.e. save with Save As with Encoding), or convert received database value into a different target encoding.

VT100 Number Keypad Escape codes when using modifiers (ctrl/shift/alt)

I'm trying to revive a pretty old MUD client to run under OS X Mojave (pretty much a telnet client that supports aliases, key bindings and triggers).
The code can be found here https://github.com/olostan/mmc
I was successfully able to run it, however it didn't correctly handle the numpad keys. As I figured out that happened because these keys weren't defined in https://github.com/olostan/mmc/blob/master/src/output.c
Once I added the following block to "keypad keys" section, it started working properly.
{ "k0", "\033Op", NULL },
{ "k1", "\033Oq", NULL },
{ "k2", "\033Or", NULL },
{ "k3", "\033Os", NULL },
{ "k4", "\033Ot", NULL },
{ "k5", "\033Ou", NULL },
{ "k6", "\033Ov", NULL },
{ "k7", "\033Ow", NULL },
{ "k8", "\033Ox", NULL },
{ "k9", "\033Oy", NULL },
Now I want to do the same for numpad keys with different modifiers (ctrl, alt, shift), for example C-k1, M-k1, S-k1, but I can't find anywhere how to correctly define escape codes for such sequence. I got the codes above from this page - https://www.gnu.org/software/screen/manual/html_node/Input-Translation.html But unfortunately it doesn't describe any combinations with modifiers.
So the question - how do I define escape codes in VT100 format for keypad combinations with modifier keys (shift, alt, ctrl)? I tried setting something like this "\033[1;5Ot" for S-k4 key combination, but none of that worked.
The question is
how do I define escape codes in VT100 format for keypad combinations with modifier keys (shift, alt, ctrl)?
The answer is that you probably can't, because terminals are unlikely to provide distinct escape codes for the numeric keypad:
VT100s never did anything like that.
xterm imitates VT100's keypad, taking into account normal and application modes (application mode sends the escape sequences you listed)
most other terminal emulators don't bother doing even that.
xterm has a feature which lets you configure it to send modified keypad keys, the modifyKeyboard resource setting:
modifyKeyboard (class ModifyKeyboard)
Normally xterm makes a special case regarding modifiers (shift,
control, etc.) to handle special keyboard layouts (legacy and
vt220). This is done to provide compatible keyboards for DEC
VT220 and related terminals that implement user-defined keys
(UDK).
The bits of the resource value selectively enable modification
of the given category when these keyboards are selected. The
default is "0":
0 The legacy/vt220 keyboards interpret only the Control-
modifier when constructing numbered function-keys. Other
special keys are not modified.
1 allows modification of the numeric keypad
2 allows modification of the editing keypad
4 allows modification of function-keys, overrides use of
Shift-modifier for UDK.
8 allows modification of other special keys
other terminals don't do that at all (a few may let you customize the keys sent, but none will have this predefined, which is what your mud client would need).

How do I allow a "SPACE" character in an AutoComplete JavaFX uneditable ComboBox?

When I type a SPACE character in an AutoComplete ComboBox, I can get the space character to be accepted except the addEventFilter code I'm using to manage it multiplies and inserts a space for each character previously typed prior to the space. You can see a screen shot example below where 3 spaces were added after the 3 characters (ive), then 4 spaces added after I include an additional charater (t), each after typing a single SPACE, and the spaces only appear after I type the next character (e.g. 'm').
I did try this with the ContolsFX AutoComplete, but it cannot handle the uneditable ComboBox - and couldn't find anything to the contrary. In the online cases I research, it was recommended to use the ComboBox's popup skin - addEventFilter to manage the SPACE character event. In nearly all the cases it was to consume() and prevent the space from selection and closing. I did not find anything that strictly allowed the space to be entered. I've tried adding the SPACE in code prior to and after this Event Code but the addEventFilter event.consume() will remove it. The SPACE character will only appear if I manage its addition within the addEventFilter method. I've tried different events such as KeyEvent.ANY, KeyEvent.KEY_TYPED, and KeyEvent.KEY_RELEASE and read the documentation on the KeyEvent, but only KeyEvent.KEY_PRESSED seems to allow the SPACE character, it just multiplies the number of spaces, and doesn't insert until the next text character.
ComboBoxListViewSkin cbSkin = cbSkin = new ComboBoxListViewSkin(cmb);
// cmb is the ComboBox
cbSkin.getPopupContent().addEventFilter(KeyEvent.KEY_PRESSED, (event) -> {
if(event.getCode() == KeyCode.SPACE){
filter += " ";
event.consume();}
});
I was able to solve my problem. The event code needed to be a part of the ComboBoxAutoComplete constructor and not part of the onKeyPressed event.
private ComboBoxListViewSkin cbSkin;
public ComboBoxAutoComplete(ComboBox<T> cmb) {
this.cmb = cmb;
cbSkin = new ComboBoxListViewSkin(cmb);
originalItems = FXCollections.observableArrayList(cmb.getItems());
cmb.setOnKeyPressed(this::handleOnKeyPressed);
cmb.setOnHidden(this::handleOnHiding);
cmb.setSkin(cbSkin);
cbSkin.getPopupContent().addEventFilter(KeyEvent.KEY_PRESSED, (event) -> {
if(event.getCode() == KeyCode.SPACE){
filter += " ";
event.consume();}
});
}

clear text field using DELETE or BACK SPACE key in webdriver

I am trying to clear a text field using this action:
emailField.sendKeys("gmail.com");
emailField.sendKeys(Keys.CONTROL,"a",Keys.DELETE);
In above code, the last line only selects the text, does not delete it, but if I separate the actions it works.
emailField.sendKeys(Keys.CONTROL,"a");
emailField.sendKeys(Keys.DELETE);
From the JavaDoc for WebElement.clear():
If this element is a text entry element, this will clear the value.
Has no effect on other elements. Text entry elements are INPUT and
TEXTAREA elements. Note that the events fired by this event may not be
as you'd expect. In particular, we don't fire any keyboard or mouse
events. If you want to ensure keyboard events are fired, consider
using something like sendKeys(CharSequence) with the backspace key. To
ensure you get a change event, consider following with a call to
sendKeys(CharSequence) with the tab key.
Most likely you simply need to call:
emailField.sendKeys("gmail.com");
emailField.clear();
But if you need the clearing to be done via the keyboard for some reason, use Keys.BACKSPACE.
keys.DELETE can not work to delete the input text,you should use keys.BACKSPACE.
emailField.sendKeys(Keys.BACKSPACE)
From the JavaDoc for Keys.chord
chord(java.lang.CharSequence... value)
Simulate pressing many keys at once in a "chord".
You should be able to use
emailField.sendKeys(Keys.chord(Keys.CONTROL,"a",Keys.DELETE));
Tested in chrome driver
WE.send_keys(' \b')
This will add space then delete it (backspace)
I use in javascript and it's working fine:
await textBox.sendKeys(value);
await textBox.sendKeys(Key.BACK_SPACE);
emailField.sendKeys(Keys.BACKSPACE)
doesn't worked for me .
I used 'Key' instead of 'Keys'
emailField.sendKeys(protractor.Key.BACKSPACE)
emailField.sendKeys(Keys.CONTROL + "a",Keys.DELETE);
In PHP:
if you use php-webdriver (https://github.com/php-webdriver/php-webdriver) you must:
use Facebook\WebDriver\WebDriverKeys AS Keys;
.
.
.
$this->driver->findElement(By::id('demo'))->sendKeys([Keys::BACKSPACE,'Any other text']);
Just adding another working C# example using the Google Chrome webdriver.
SendKeys only takes one parameter so created a string with the Crtl + A. This code sequence will select the current text in the field then delete the text.
Code example:
var crtlA = Keys.Control + "a";
driver.FindElement(By.XPath("//div[3]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div/span/input")).SendKeys(crtlA); Wait(5000); // Select current text
driver.FindElement(By.XPath("//div[3]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div/span/input")).SendKeys(Keys.Delete); Wait(5000); // Clear current text
driver.FindElement(By.XPath("//div[3]/div[1]/div[2]/div/div[2]/div[2]/div/div/div[1]/div/span/input")).SendKeys(newItemSku); Wait(5000); // Input SKU name
1. in WebdriverIO, i tried to edit the text by clear text (which contains special charactes like #, +, _) in text field by below following step. Eventhough it was not successful.
example: text=> abc+1234#gmail.com
step1:browser.clearElement(selector);
step2:browser.execute(function () {
document.querySelector(>>>Cssselector<<<).value="";
});
step3: browser.doubleClick(selector);
browser.keys("Delete");
step4: browser.click(selector);
browser.keys(['Meta',a]);
browser.keys('Meta');
browser.keys('Delete');
Note: below step is resolved this issue.
var count= browser.getAttribute(selector, value).length;
for (var i=0;i<count;i++)
{
if (browser.getAttribute(selector, value)=='')
break;
}
else
{
browser.doubleClick(selector);
browser.keys("Delete");
}
browser.pause(200);
// it will clear your text field easily.
Note:
You can add the new text now.

How to apply a function before comparison in an esqueleto query

For a query simple as that
runDb . select . from $ \cell -> do
where_ $ cell ^. CellCode ==. val "x"
return cell
I want to apply a function before the comparison of the field value with "x". The reason is that the cell code has trailing spaces in the database and nothing easier than trimming them away, e.g. with strip from Data.Text. However, my initial approach of using fmap (twice) resulted in
No Instance for (Functor SqlExpr)
I know that there are functions provides by Esqueleto, like just, that accomplish similar things specifically (I couldn't find the implementation of just, though).
Is there a way to apply any function on the packed value?
While writing: in my specific case, I just might want to use like.
EDIT: Added the specific function I want to apply.
What kind of function to you want to apply?
Here is how someone added the ability to call the chr() function in a query:
https://github.com/krisajenkins/esqueleto/commit/fa1d1c888770e297fef52d76b6cb68342a6c0376
If it is a built-in function (or a user-definable function), perhaps you can do something similar.
See here for a post that adds the postgresql function trim:
import Database.Esqueleto.Internal.Sql
trim :: (IsString s) => SqlExpr (Value s) -> SqlExpr (Value s) -> SqlExpr (Value s)
trim pattern target =
unsafeSqlFunction "trim" (unsafeSqlBinOp "FROM" pattern target)
(If you're not using postgres, you may need to consult the documentation from your database to find if it supports something similar.)
unsafeSqlFunction can be used to import any function your database supports, but it is unsafe because you have the responsibility to make sure the type signature is actually what your database expects. The name will be copied literally to your SQL.
unsafeSqlBinOp is similar, but it defines a binary operation: unsafeSqlBinOp "FROM" "a" "b" is translated into the SQL "a" FROM "b".
With this, you should be able to do:
runDb . select . from $ \cell -> do
where_ $ trim " " (cell ^. CellCode) ==. val "x"
return cell

Resources