Dispatcher to Submit Keypresses from the Init() or Using Action() in JScripts

Over the years I’ve used a variety of methods to call things like PageDown from within my scripts, some more pretty than others.

You would think that in the Init() you can just call controller.PageDown() and all is good in the world.

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

package MForms.JScript
{
	class showPageDown
	{
		var gDebug = null;
		var gController = null;
		var gContent = null;

		public function Init(element: Object, args: Object, controller : Object, debug : Object)
		{
			gDebug = debug;
			gController = controller;
			gContent = controller.RenderEngine.Content;

			gController.PageDown();
		}

	}
}

And if you test with the Script tool within Smart Office it is…until you deploy it and then you get the “Duplicate request skipped” message in the logs 😦

Not a drama – in C# it’s pretty easy to deal with, you drop it on to the dispatcher with the priority as background so it will be executed after the Init() finishes. But in JScript, it’s a little less obvious how to do this. I managed to figure out the correct incantations a while ago but never got around to posting about it, and then of-course when I came to write a new script (importing of the exchange rates for a customer) it took a while to find the script that I had written. So now I’ve thrown together a post so it’s easy for me to find next time 🙂

Oddly, it is a lot easier than expected to get the syntax correct and we can of-course use it for other key entry, and in the Exchange Rates import script I end up using it for simulating F3, Enter, ListOptions and of-course PageDowns.

Anyway, here’s the example script.

import System;
import System.Windows;
import System.Windows.Controls;
import MForms;

import Mango.UI.Services;
import System.Windows.Threading;

package MForms.JScript
{
	class showPageDown
	{
		var gDebug = null;
		var gController = null;
		var gContent = null;

		public function Init(element: Object, args: Object, controller : Object, debug : Object)
		{
			gDebug = debug;
			gController = controller;
			gContent = controller.RenderEngine.Content;

			//gController.PageDown();
			DashboardService.Current.Dispatcher.BeginInvoke(Action(pageDown), DispatcherPriority.Background);
		}

		private function pageDown()
		{
			gController.PageDown();
		}
	}
}
This entry was posted in Development, M3 / MoveX. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s