I'm using http://onehackoranother.com/projects/jquery/boxy/
How to close boxy window on press ESC key?
if (this.options.closeable) {
jQuery(document.body).bind('keypress.boxy', function(evt) {
var key = evt.which || evt.keyCode;
if (key == 27) {
self.hide();
jQuery(document.body).unbind('keypress.boxy');
}
});
}
Related
$("#btnCrpPhoto").on("click", function () {
console.log("clickphoto");
console.log($('#hfX').val());
console.log($('#hfY').val());
console.log($('#hfHeight').val());
console.log($('#hfWidth').val());
}
insted of this i want to save on key press
document.querySelector('#imageSize').addEventListener('keyup', function (e) {
if (e.which == 65) {
}
you can use this function.
I am using this to detect keystrokes on my app...
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown
handler:^NSEvent * (NSEvent * theEvent)
OK I can use theEvent to know what characters were typed and know if a shift was pressed using this:
NSString *typedKey = theEvent.charactersIgnoringModifiers;
BOOL shiftDetected = [theEvent modifierFlags] & NSShiftKeyMask;
My App has an interface displayed with some buttons and I am allowing the keyboard to be used instead of clicking on the buttons. This interface has 3 buttons in particular that has a second function.
For example: the first button has 2 functions, A and B but just the A label is displayed on that button. Lets say I specify that the letter Q is the keyboard shortcut for that button. If the user presses Q function A is executed. If the user presses Shift Q then function B is executed.
But this is the problem. I need to detect all presses or releases of the Shift, because the moment the user presses Shift I have to change the label of that button from A to B, so the user knows that now that button will lead to the execution of function B instead of A. Like a keyboard that will change from lowercase to uppercase while Shift is being hold and change back to lowercase the moment Shift is released.
How do I do that?
I created a simple project using addLocalMonitorForEvents function. Please check my code, it is Swift code but I think it should be as same as objective c.
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
NSEvent.addLocalMonitorForEvents(matching: [.flagsChanged, .keyDown]) { (theEvent) -> NSEvent? in
if theEvent.modifierFlags.contains(.shift) {
if theEvent.keyCode == 56 { // this is Shif key
print("Shift START!")
}
else {
print("Shift pressed with keycode \(theEvent.keyCode)")
}
}
else {
if theEvent.keyCode == 56 { // this is Shif key
print("Shift END!")
}
else {
print("Normal keycode \(theEvent.keyCode)")
}
}
return theEvent
}
}
This is Objective c:
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskFlagsChanged|NSEventMaskKeyDown handler:^NSEvent * (NSEvent * theEvent) {
if ([theEvent modifierFlags] & NSEventModifierFlagShift) {
if (theEvent.keyCode == 56) { // this is Shif key
NSLog(#"Shift START");
}
else {
NSLog(#"Shift pressed with keycode %d", theEvent.keyCode);
}
}
else {
if (theEvent.keyCode == 56) { // this is Shif key
NSLog(#"Shift END");
}
else {
NSLog(#"Normal keycode %d", theEvent.keyCode);
}
}
return theEvent;
}];
Just copy and paste this part to your AppDelegate for quick testing.
when I resized the firefox window to just not display my add-on's toggleButton, then resized the firefox window to display my add-on's toggleButton. The badgeColor was displayed with default color(red).
How should I do and solve this problem? And is this the firefox's bug?
var {ToggleButton} = require("sdk/ui/button/toggle");
var button = ToggleButton({
id:"aaaa",
label:"aaaa",
icon:{
"16":"./aaaa-16.png",
"32":"./aaaa-32.png",
"64":"./aaaa-64.png",
},
onChange:changed,
badge:"0",
badgeColor:"#A9A9A9",
});
function changed(state) {
if (button.badge == "1") {
// code
button.badge = "0";
} else {
button.badge = "1";
}
if (state.checked) {
// code
button.badgeColor = "#20B2AA";
}
else {
button.badgeColor = "#A9A9A9";
}
}
I want to catch both the single left click and the ctrl + left click in as2.
I am using FlashDevelop and coded this (it works):
_mc._back.onRelease = function() :Void
{
var args:Array = new Array();
args.push((_root._xmouse - this._parent._posMiniMapX) * this._parent._ratio);
args.push((_root._ymouse - this._parent._posMiniMapY) * this._parent._ratio + this._parent._bpa / this._parent._ratio);
fscommand("MoveCameraMiniMap", args);
}
How can I handle the both event?
Thank you.
the approach that I've usually taken is to listen to keyboard events on the CTRL key then evaluate that onRelease to determine the correct action.
But you could simply check the key.isDown status within the onRelease
_mc._back.onRelease = function() :Void {
if(Key.isDown(17)) {
// do CTRL + mouse action
} else {
// do standard action
}
}
On my scriptUI panel, I have a button. How can I detect whether the user is holding the shift key when they click on the button?
You can add an eventListener to your button.
var win = new Window ("dialog");
win.aButton = win.add ("button", undefined, "Button");
win.aButton.addEventListener ("click", function (k) {
if (k.shiftKey) {
alert("foo");
}else{
alert("bah");
}
});
win.show ();