How to invoke a method only while button is pressed? - dart

I am trying to make a voice command button that works with while pressed. I have 2 methods, one button calls the first method which starts recording, the 2nd stops the recording. How can i make it so that i use one button (while pressed) or for example 1 method on press the 2nd method on button release? I don't know what to use.

Use GestureDetector as your widget and use onLongPressUp and onLongPressStart respectively
GestureDetector(
onLongPressStart: _startRec, // start recording when long pressed
onLongPressUp: _stopRec, // stop recording when released
child: Text("Hold to record"),
);

Related

Flutter: How to detect keyboard press Enter?

TextEditingController.addListener() registers a callback for when the text changes. This seems to also be triggered by pressing the Enter button, opening/closing the keyboard (changing focus).
How do i register that it was the enter that was pressed so i can, for example, invoke an API?
The current way i achieve this is by listening on the FocusNode to detect focus change. Focus is removed from the FocusNode when pressing enter, and the keyboard closes. Is this the right way to do it?
There is a onSubmitted property which accepts a ValueChanged callback. onSubmitted is triggered once the user press done after editing.
Hope that helps!

combobox steal keyboard from main window in pyqt

I'm writing a small pyqt program. I want the main window to to react to arrow movement. I added an event to my MainGui class, keyPressEvent, that handle this. The event work fine as long as I don't press certain buttons such as Key_Up or Key_Down are directed to my (currently only) QComboBox and not to my mainGui. I tried to give the focus to mainGui after each paintEvent but then I need to double click on buttons/comboBox.
Then I tried to use the MousePressEvent to check if a certain element is under the mouse. This work fine with the comboBox, but not with the button.
So, how can I direct key events to the mainGui or give the focus to QButtons?
I used eventFilter to identify when the mouse enter the QPushButton and give it focus:
def eventFilter(self,source,event):
if event.type() == QtCore.QEvent.HoverMove:
if self.execButton.underMouse():
self.execButton.setFocus()
self.keepFocus=False
else :
self.keepFocus=True
keepFocus is a flag I initialized in the __init__ function of the class. I added this part at the paintEvent function
if self.keepFocus:
self.setFocus()
else:
self.keepFocus = True
Now, I keep the focus at the MainGui and I only give it to the button when the mouse hove over it. If I do another action (like pressing a mouse button or a keyboard key) the focus is given back to the MainGui. This will create some buggy filling (For example, I need to press twice a keyboard key before the first response) but this is workable.

mouseUp firing after button click in mobile Safari (iOS simulator)

I'm trying to build an editing view for a mobile app powered by Backbone.js and Trigger.io. The user goes to a note view and makes changes by tapping "edit" in the top right. When the "edit" button is tapped, we focus on the textarea containing the content and the "edit" button goes away and a "save" button appears. Whenever "edit" is tapped, however, a mouseUp event is firing which results in the textarea losing focus.
The mouseUp event does not fire if the edit button gets hidden and nothing replaces it. The mouseUp does fire if the edit button either A) remains or B) is hidden and save button replaces it.
The only way I've found to fix it is by setting a 200ms+ timeout between hiding the "edit" button and displaying the "save" button.
Is there something with mouseup events firing after click events and/or having them target separate elements? I'd post code but it's all over the place and would not provide much context. If you really need the code, I can post it in parts.
I believe iOs places a delay on the mouseup, to determine if a long touch is being performed. This might help:
http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone

How to remove click handler in windows phone 7?

In a page one image control is there.when click on that i am showing big image.in some condition i don't want to show.For that i am trying to remove click handler event.please tell me how to remove image mouse enter click event in wp.
You can remove a event handler from a event by using the -= operator.
Example for removing a event handler called OnTap_Handler from the Tap event of a Image.
Image.Tap -= OnTap_Handler;

jQuery - Trigger() once every click

I've ran into a problem with something quite simple. When I click #mybutton I want to trigger a click on another button.
$('#mybutton').click(function(){
$('#otherbutton').trigger('click');
});
When I first click #mybutton the #otherbutton will trigger once. When I click #mybutton the second time the #otherbutton will trigger twice. When I click #mybutton the third time the #otherbutton will trigger three times...and so on.
How can I stop this so that #otherbutton will only trigger once for each click of #mybutton?
EDIT
Aha! I've just realised this is due to fancybox (where the buttons live).
The buttons are clicked from fancybox popop, which is also triggered to open every time before the buttons are clicked.
$('#planApp-link').fancybox().trigger('click');
I'm still not sure how to prevent this from happenning.
instead of using trigger("click") u can use
$('#otherbutton').click();
this function it ll trigger the click function
$(".clas1").on("click",function(){
$(".clas2").click();
});
$(".clas2").on("click",function(){
alert("div2");
});
.

Resources