event-handling

Handle mouse event anywhere with JavaFX

。_饼干妹妹 提交于 2019-11-27 11:36:24
问题 I have a JavaFX application, and I would like to add an event handler for a mouse click anywhere within the scene. The following approach works ok, but not exactly in the way I want to. Here is a sample to illustrate the problem: public void start(Stage primaryStage) { root = new AnchorPane(); scene = new Scene(root,500,200); scene.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { System.out.println("mouse click detected! "+event.getSource());

Android:how to get any KeyPress event with example?

可紊 提交于 2019-11-27 11:33:07
问题 i want to get the key value when user pressed any key and also perform action based on the key pressed in android. e.g. if user pressed 'A' key then i want to get that value,compare,do something. 回答1: Answer to this question should be twofold. It is determined by the way how the key was generated. If it was press on the hardware key, then both approaches described below are valid. If it was press on the software key, then it depends on actual context. 1.) If key was result of the pressing on

How to handle add to list event?

*爱你&永不变心* 提交于 2019-11-27 11:27:22
I have a list like this: List<Controls> list = new List<Controls> How to handle adding new position to this list? When I do: myObject.myList.Add(new Control()); I would like to do something like this in my object: myList.AddingEvent += HandleAddingEvent And then in my HandleAddingEvent delegate handling adding position to this list. How should I handle adding new position event? How can I make this event available? Paolo Tedesco You could inherit from List and add your own handler, something like using System; using System.Collections.Generic; namespace test { class Program { class MyList<T> :

Raising C# events with an extension method - is it bad?

Deadly 提交于 2019-11-27 11:12:05
We're all familiar with the horror that is C# event declaration. To ensure thread-safety, the standard is to write something like this : public event EventHandler SomethingHappened; protected virtual void OnSomethingHappened(EventArgs e) { var handler = SomethingHappened; if (handler != null) handler(this, e); } Recently in some other question on this board (which I can't find now), someone pointed out that extension methods could be used nicely in this scenario. Here's one way to do it: static public class EventExtensions { static public void RaiseEvent(this EventHandler @event, object sender

How to decode character pressed from jQuery's keydown()'s event handler

余生长醉 提交于 2019-11-27 11:11:06
I need to figure out which character was typed into a text field from within the handler that is called by jQuery's keydown function. key.which gives me only the keycode, but I need to figure out which ASCII character key represents. How do I do this? For character input, it is suggested you use keypress() , which will report the actual ASCII code for the character pressed. It automatically takes care of letter case, and ignores non-character presses. In either case, you can use fromCharCode() to convert to a string representation. E.g. var c = String.fromCharCode(e.which) // or e.keyCode Just

Tkinter: Wait for item in queue

偶尔善良 提交于 2019-11-27 10:39:43
问题 I’m using a queue to exchange messages between a background thread and a Tk GUI application. Currently, this is done by calling a query method every now and then. def read_queue(self): try: self.process(self.queue.get(False)) # non-blocking except Queue.Empty: pass finally: self.after(UPDATE_TIME, self.read_queue) The problem with this approach is that if UPDATE_TIME is too large, the application will process new items slower than possible. If it is too small, Tk spends most of the time

Why people use message/event buses in their code? [closed]

Deadly 提交于 2019-11-27 10:27:31
I think that you have heard of message/event buses, it's the single place when all events in the system flow. Similar architectures are found in computer's motherboards and LAN networks. It's a good approach for motherboards and networks as it reduces the number of wires, but is it good for software development? We don't have such restrictions as electronics does. The simplest implementation of message bus/event bus can be like: class EventBus { void addListener(EventBusListener l}{...} void fireEvent(Event e) {...} } Posting events is done with bus.fireEvent(event), receiving messages is

jQuery Multiple Event Handlers - How to Cancel?

故事扮演 提交于 2019-11-27 09:58:15
问题 I have two functions bound to a click event at two different times (using jQuery). The order in which they are fired is significant. They are firing in the correct order. The problem is, when the first function returns false, the second function is still firing! How can I properly cancel the event? Example code: $(document).click(function() { alert('a'); return false; }); $(document).click(function() { alert('b'); }); You will still see the "b" alert message when clicking the page. This is

Why is a value copy of MainForm created when method is called or invoked cross thread?

北战南征 提交于 2019-11-27 08:33:35
问题 Update: I think it has something to do with lazy instantiation of the window handle for MainForm - but haven't been able to work out quite how that would result in the behavior seen here. The application requests data via 3rd party COM interface providing a callback to process the results. In the callback, the UI needs to be updated - but the update doesn't work as expected. It's as if a value copy of MainForm had been created, when MainForm.DataReady is called or invoked directly cross

What exactly $event object do in Angular 2?

ⅰ亾dé卋堺 提交于 2019-11-27 08:17:24
I am bit confused what exactly $event doing here and what is the difference between this two examples <button (click)="clicked($event)"></button> @Component(...) class MyComponent { clicked(event) { event.preventDefault(); } } and <button (click)="clicked()">Click</button> @Component(...) class MyComponent { clicked(event) { } } $event is the event itself. The event binding (someevent) allows to bind to DOM events and to EventEmitter events. The syntax is exactly the same. For DOM events $event is the MouseEvent , KeyboardEvent , or the event value of the type of whatever event you listen to.