I to remap the ` key so that when I hold it it behave the same way as holding the alt key. For instance holding ` and pressing tab should behave as alt+tab.
I tried this, but it doesn't work. What am I doing wrong?
hs.hotkey.bind({}, "`", function() hs.eventtap.keyStroke({"alt"},"") end)
Create an eventtap and hook into the keyDown event. Determine the keycode for the backtick (50 for my keyboard layout) and post key events to simulate that the alt (option) key was pressed. Finally return true to surpress the original key (`).
local events = hs.eventtap.event.types
keyboardTracker = hs.eventtap.new({ events.keyDown }, function (e)
local keyCode = e:getKeyCode()
if keyCode == 50 then
hs.eventtap.event.newKeyEvent(hs.keycodes.map.alt,true):post()
hs.eventtap.event.newKeyEvent(hs.keycodes.map.alt,true):post()
return true
end
end)
keyboardTracker:start()
Related
I'm new to React and I have a problem which I don't know how to solve.
I have a state which tracks what I type on the textInput. But when I console.log the input that I type on the textInput, it shows the whole chunks like 'a', 'ab', 'abc' as I type. I want to be able to have control over each input I type like 'a' 'b' 'c', not the whole input like 'abc'. For this, I've tried the map and split function, which made some errors, unfortunately.
Can anyone offer some advice? I'm attaching some of the lines below.
const Words = () => {
const [correctLetters, setCorrectLetters] = useState([]);
const correctLettersHandler = (input) => {
//console.log(input) -> it shows the whole inputs
//const letter = input.map((letter) => letter.split("")); -> failed try
setCorrectLetters(input);
}
return (
<View>
<TextInput
value={correctLetters}
onChangeTedt={correctLettersHandler}
</View>
}
I recommend you take a look at The KeyboardEvent Object to get a full insight on the keyboard events.
At the bottom there are the event types that belong to the KeyboardEvent Object (already mentioned by Derek in a comment to the question):
onkeydown, the event that occurs when the user is pressing a key
onkeypress, the event that occurs when the user presses a key
onkeyup, the event that occurs when the user releases a key
I have tabs with forms and I want ask the user to confirm or discard their changes when changing tabs. My current code works
<uib-tab heading="..." index="3" deselect="main.onDeselect($event)" ... >
this.onDeselect = function($event) {
if(...isDirty...) {
if($window.confirm("Do you want to discard?")) {
... discard (and go to new tab) ...
} else {
$event.preventDefault(); //stays on current tab
}
}
}
The problem is I want to change confirm to javascript dialog and I will get result in callback.
I planed to preventDefault() all and then switch manually, but I cannot figure out where to get new tab id.
Any solution is appreciated. Even if it is easier in other tab implementations.
I use AngularJS v1.4.7, ui-bootstrap-tpls-1.3.3.min.js
You can make use of $selectedIndex and the active property for that purpose. See this Plunk
One thing to be noted here is that when we manually change the active property, it again fires the deselect event which needed to be handled. Otherwise it seems to do what you wanted.
Edit
Indeed as noted in the comments, the deselect carries the HTML index rather than what is passed in in the tab index property. A workaround could be in this: Another Plunk. Here I'm pulling the actual index from the HTML index.
And a little research indicates that this issue might as well be fixed already with 3.0 bootstrap tpl See this.
I spent some time with different approaches and this one is stable for some time. What I do is to prevent deselect at the beginning and set the new tab in callback if confirmed to loose changes...
this.onDeselect = function($event, $selectedIndex) {
var me = this;
if(this.tabs.eventDirty || this.tabs.locationDirty || this.tabs.contractDirty) {
$event.preventDefault();
var alert = $mdDialog.confirm({
title: 'Upozornění',
textContent: 'Na záložce jsou neuložené změny. Přejete si tyto změny zrušit a přejít na novou záložku?',
ok: 'Přijít o změny',
cancel: 'Zůstat na záložce'
});
$mdDialog
.show( alert )
.then(function() {
$rootScope.$emit("discardChanges");
me.tabs.activeTab = $selectedIndex;
})
}
};
How to do this requirement using backbone?
When I enter values in first text field second field must be disabled and when I delete the data from first field second field must be enabled and vice versa using backbone
I searched many placed but have not got what I needed.
To Enable / Disable input field in backbone as you type,you need to bind the keyup event to an event handler in your view. This can be done by adding the corresponding entry in the events hash.
Binding keyup event in your Backbone Views :
events : {
"keyup #first_text" : "firstFunction",
},
// THE EVENT HANDLER FUNCTION.
firstFunction : function(e) {
if(e.currentTarget.value && e.currentTarget.value.trim() != "") {
$("#input_text").prop("disabled",true);
}
else {
$("#input_text").prop("disabled",false);
}
},
Fiddle : https://jsfiddle.net/rnwvf3r9/
enter code hereI have a window in which I have a form with trigger fields. So by trigerring I mean , if I select a value from first combo, its trigerring the succeding combos with their's first values. This is working fine when I open the window for the first time. But if close it and open it for the second time, it will generate error as me.store.loading is undefined.
I am using on load event of combo to fire the next combo with its first value. Please see code below which I have put in the render event of a field in that window.
Thanks,
sj
me.control({
'addinp #renderCmp':{
render:me.registerTriggerCalls
}
})
registerTriggerCalls : function() {
var stcombo = Ext.getCmp('StField');
stcombo.store.on('load', function(store, record, opts)
{debugger;
if (store.totalCount <= 0)
{ return; }
stcombo.setValue(store.getAt(0).data.stThru);
stcombo.fireEvent('select', stcombo);
});
var adcombo = Ext.getCmp('AdField');
adcombo.store.on('load', function(store, record, opts)
{
if (store.totalCount <= 0)
{ return; }
adcombo.setValue(store.getAt(0).data.adDate);
adcombo.fireEvent('select', adcombo);
});
}
When does the store get created/destroyed? Are you creating a new store with each combo box or are you reusing a global store each time?
In the comments above, I give you a way to troubleshoot, but if you're reusing the same store object over and over, you either need to use a managed listener (preferred) or unregister your handlers when your combo boxes are destroyed.
var stcombo = Ext.getCmp('StField');
stcombo.mon(store, 'load', function(store, record, opts)
{
if (store.totalCount <= 0)
{ return; }
stcombo.setValue(store.getAt(0).data.stThru);
stcombo.fireEvent('select', stcombo);
});
var adcombo = Ext.getCmp('AdField');
adcombo.mon(store, 'load', function(store, record, opts)
{
if (store.totalCount <= 0)
{ return; }
adcombo.setValue(store.getAt(0).data.adDate);
adcombo.fireEvent('select', adcombo);
});
Assuming that's the case, what's happening is that the life span of your store and your combo box is disconnected. The listeners are tied to the store's life span which doesn't have visibility to the combo box's life span. Hence, the old listeners don't get removed until the store is destroyed which is obviously bad -- for a number of reasons -- but causing your exception because the closure references a destroyed combo box.
A managed listener solves this by essentially tying the listener's life span to the combo box instead of the store.
I have implemented scrollable extjs tab panel in our product. But I also need to support accesskey functionality. For example, an "Alt + P" keystroke will open up one of tab. Does anyone have any experience about implementing this?
The core to this is creating a keymap to recognise you are pressing a combination of keys, once this is detected you can then add a custom handler.
See here: http://dev.sencha.com/deploy/dev/docs/?class=Ext.KeyMap
eg:
var map = new Ext.KeyMap("my-element", [
{
key: [10,13],
fn: function(){ alert("Return was pressed"); }
}, {
key: "abc",
fn: function(){ alert('a, b or c was pressed'); }
}, {
key: "\t",
ctrl:true,
shift:true,
fn: function(){ alert('Control + shift + tab was pressed.'); }
}
]);
Above are a number of sample mappings, you simply replace 'my-element' with the element you wish to look for the key presses on (so which element when selected will detect them). If you wish to have APPLICATION wide key mapping, this element should either be the body of the page, the window itself or the ExtJS Viewport (if you are using one) / Master element. This will mean you can be within any area of your application and the keypress is detected. The subsequent behaviour you define under the 'fn' property (i.e. change tab etc)...