Is there a way to capture the key being pressed in a 'key_press_event'? - event-handling

I am trying to build a basic interface using pyGTK, where based on the key being pressed, I evoke different functions.
I understand that using the 'connect' method, I can capture events such as a keypress or a click, like so:
self.btn1.connect("clicked", self.funcRec)
self.btn1.connect("key_press_event", self.funcRec)
Doing this will call the funcRec function when there is a key press event, or when the button is being clicked.
But I am not able to find a way to capture the actual key being pressed and trigger different functions. Is there a way to do this?

I found a way. I used a function that captures the event and gets the value of the key press event.
First you 'connect' and get the 'key_press_event' and trigger a callback function
self.connect("key-press-event", self.on_key_down)
where 'on_key_down' callback function is defined as,
def on_key_down(self, widget, event):
key = event.keyval
if key == gtk.keysyms.Right:
self.onRightPress(self, widget)
if key == gtk.keysyms.Left:
self.onRightPress(self, widget)

Related

Is there a way to execute default TextField key event handler from Action

I have a textfield which has an ancester (maybe multiple) of type Action, which every one of them has a minimum of one ancestor of type Shortcut.
One intent shortcut defined is the one that catches any of the four arrow key pressed.
I want to execute the default TextField behaviour when arrow key pressed is left or right (move cursor left or right) if certain state is present.
Is there a way, once the CallbackAction is executed?
* I know to execute next CallbackAction for that intent with Actions.maybeInvoke<ArrowKeyIntent>(context, intent) but I don't know how to execute default textfield behavior.
Thank you.

Detect what button is pressed

Suppose there are several buttons created programmatically, and there is a common button handler.
onButtonClicked(){
// print button attribute
}
How to understand inside the handler which button is pressed?
WITHOUT passing something special inside the function call. That won't do:
onButtonClicked("button" + i);
In JavaScript, for example, inside the handler, there is $(this), which immediately "understands" which button is pressed.
Maybe there is a similar mechanism in Flutter? I want to hang attributes on the button (without knowing which ones in advance), and then have access to them in the handler.
I think there is only one way to write the print('your function name') inside your function
Just pass the Parameter inside your method.
for example:-
onButtonClicked(Parameter){
// print button attribute
print("${parameter}");
}
And pass different parameter for different buttons.

MATLAB appdesigner chage selected cell in UItable

I have a UItable in MATLAB appdesigner, let's say 'app.UITable'. Can I change the selected cell via callback function? For example, I would like to move one cell down when Enter key is pressed. For what I read, new MATLAB uiobjects do not accept button-press callbacks. Is that true? or is there any known hack to do that? Thank you.
Related post
As of R2018b, new figure interactions were added. Regarding your specific question, you should take a look at these new keyboard interaction callbacks:
KeyPressFcn - This callback function executes when the user presses a key while the figure or a child object has focus. If the user presses a key on a UIControl or Table component, the callback does not execute unless the Enable property is set to 'off'.
KeyReleaseFcn - This callback function executes when the user presses [sic] a key while the figure or a child object has focus. If the user releases a key on a UIControl or Table component, the callback does not execute unless the Enable property is set to 'off'.
WindowKeyPressFcn - This callback function executes when the user presses a key while the figure or a child object has focus.
WindowKeyReleaseFcn - This callback function executes when the user releases a key while the figure or a child object has focus..
See also: R2018 Release notes.

GWT how to change textbox without running change handler

I am using GWT. I have a textbox and a drop down list box that have change handlers on them. I also sometimes change the text or selected value from the source code but I don't want the change handler to run when I do this, I only want it to run when the user changes it.
How can I implement this?
For the TextBox, use setValue(T value, boolean fireEvents) using false as second argument, to avoid firing any ValueChangeEvent.
For the ListBox, when you call setSelectedIndex(int index) or setItemSelected(int index, boolean selected) the ChangeEvent is never fired, so you are free to use them programmatically and rely on the ChangeHandler on user action.

tinyMCE alert what you just wrote

In the tinyMCE init editor,
How can i in setup do:
ed.onKeyDown.add(function (ed, evt) {
// alert the character you just typed
});
Say if you type "a" a alert should come up with "a"
The evt.keyCode property contains the code of the pressed key, so you can do this:
alert(String.fromCharCode(evt.keyCode));
Note, however, that this will also trigger an alert when a special key is pressed (e.g. shift), so you might want to prevent that by checking other properties of the evt object (which is an instance of DOM Event). See the documentation for keyboard event objects at https://developer.mozilla.org/en/DOM/KeyboardEvent.
Edit: Use onKeyPress instead of onKeyDown, as onKeyDown might return incorrect key codes in some browsers.