How to Simulate a Keyboard Event in Dart HTML - html

1. Problem and Context
I'm trying to create a browser extension with Dart, more specifically, one that deals with adding keyboard shortcuts to certain websites.
To guarantee better TDD, I'm trying to simulate keyboard events during the tests. However, it seems like many things have changed when it comes to Dart's HTML APIs and I haven't been able to figure out how to make them work.
2. What I'm Trying
I would like to register a specific keystroke — so the generic KeyboardEvent won't cut it apparently, only the KeyEvent class can handle that. So far, I'm trying something like this:
document.body.dispatchEvent(KeyEvent('keypress', keyCode: 65, charCode: 97));
From which I receive an error close to this:
Error: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.
I've also tried the code above with document, document.window and window, none worked. Something similar can be found in the KeyEvent documentation. However, they mention adding to a Stream, which I don't think is possible. It would have to be a Sink instead.
If I'm not able to solve this via dispatching events, I think I'll have to simply inject mocks into the tests.
3. More Resources
2 outdated answers which have helped me so far were:
dart how to create, listen, and emits custom event?
How do I listen for custom events in Dart?

Related

Custom JSON renderer in AEM/Sling

I've been playing around with this for a while now, and I think, I've - almost - cracked it, but I am still not fully satisfied with my solution.
So, what I want to do, is having a piece of content, a list of items, which would have two views: The standard HTML one, so people can view and edit it; and then a JSON endpoint for other services to consume.
First I thought it's a simple matter of creating two JSP scripts to render the content:
/apps/my-stuff/components/list-page/html.jsp
/apps/my-stuff/components/list-page/json.jsp
However the Apache Sling DefaultServlet seems to be rather ignorant of the json.jsp script.
As a second attempt, I created another script, in /apps/foundation/components/primary/cq/Page/json.jsp which will be actually called, and renders the page, as I expected. However there are a couple of worries/questions regarding this:
First of all, why is this being honoured by the system, and not the one in the more specific place?
The documentation states, that to find the appropriate renderer, first sling:resourceType will be inspected, then sling:resourceSuperType and then, only as a fallback will jcr:PrimaryType checked. However I think this is rather: jcr:PrimaryType, then the DefaultServlet, and then all the other things.
Most worryingly however, I have to admit, this is rather generic, so it'll break all the contnet with jcr:PrmaryType = Page, so that could have some side-effects.
A solution could be creating a new type: ListPage extends Page; and then create a renderer for that in /apps/foundation.... However I have this bad feeling, that might introduce other problems.
So my question is two fold: What is the proper way of doing this, and/or what am I missing from the way the URL -> script resolution is working in AEM/Sling. (Because it seems to be slightly different that described here and here.)
(Obviously I am trying to keep the default JSON renderer for other pages, as that might be needed for other things in the page. I am not even sure, changing this one page won't break the UI for this particular page...)
However the Apache Sling DefaultServlet seems to be rather ignorant of the json.jsp script.
Have you tried renaming your JSP like so: "list-page.json.jsp"?
If you're using AEM 6.3, you should look at Sling model Exporters. They allow you to automatically register a servlet against your Sling Model (that you can create to model your list content). That servlet can generate a JSON representation of the model for you using Jackson.
If you're not using AEM 6.3, I would suggest you create a servlet registered against your resource type and use an additional selector.
#SlingServlet(
selectors = "json",
resourceType = "my-stuff/components/list-page",
methods = "GET")
More information on Sling Servlets can be found here.

Can an embedded cocos2d-js app call back out to c++?

I'm researching the possibility of using cocos2d-js by embedding it as a view inside an existing iOS app. In order to make this work, I'm going to need 2-way communication between cocos2d and the surrounding application.
After some initial investigation, I have determined that it is possible to call in to cocos using ScriptingCore:
ScriptingCore* sc = ScriptingCore::getInstance();
jsval outVal;
sc->evalString("function()", &outVal);
My question, then, is around doing the reverse. It is possible to (e.g. in response to user input) call back out of cocos2d-js to C++? Ideally, there would be a way to register a callback with ScriptingCore which could be invoked from JavaScript.
I believe it can be done, but I have not tried myself, nor can I find a good and concise example.
All I can do is point you at SuperSuraccoon's Bluetooth example and it's git page, which apparently does both ways communication between C++ and JS code.

Firing a KeyDown event in WinRT

Is there a way to fire a custom KeyUp/KeyDown event on the CoreWindow?
For example, take the following event:http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.core.corewindow.keyup.aspx.
My application already uses CoreWindow::KeyUp and CoreWindow::KeyDown to handle events. I am trying to test that the correct delegates are being attached and thus called when an event happens.
Note that I can't call the delegate function directly since it will not test the fact that the delegate is attached to the event.
I am looking for an answer similar to https://stackoverflow.com/a/3977396/756356.
I doubt that's possible because it sounds like something possibly interfering with the sandbox concept of modern apps. You could maybe insert some layer between the CoreWindow and your handlers and bubble the events through that layer to make is possible to raise your proxy events. I would recommend against that though since that just adds code you don't need.

Status listener on mediaplayer object in javafx 2

I'm trying to make a media player with playlist in Javafx2.
I'm struggling because I want the playlist to advance to the next song when the current song ends. I was expecting a listener interface that I could implement in my playlist class but all that is on offer is that of a runnable.
Does anyone have any experience using this API that may help me?
Implement a Runnable for the setOnEndOfMedia method.
See this sample code which plays a list of audio files.
I think the media events should have been handled by EventHandlers rather than Runnables and requested that they be updated to work with EventHandlers but that requires a possibly incompatible API change which hasn't been implemented yet. So for now just use the Runnables - they work fine even though their method signatures are inconsistent with the rest of the JavaFX system.

What exactly this method do ? addActionListener

What exactly will this addActionListener Do.....we we call button.addActionListener(this) what will happen
It basically adds this (the current object) to a list of objects that will be notified when the component has an action performed on it, such as a button being pressed.
It's a way of registering your interest in what is happening to the component and is useful in that you don't have to keep polling a component to check its status.
Your object (or class, really) simply implements the interface methods for listening (such as actionPerformed) and that method will be called for each event that happens.
The Java tutorials have a large variety of different articles on the various listeners that you're likely to use.