Extra Code Functions - FlushKeys & Real Millisecs

Monkey Forums/Monkey Code/Extra Code Functions - FlushKeys & Real Millisecs

therevills(Posted 2011) [#1]
Now as a Google code project called "diddy" (as in Diddy Kong ;)).

http://code.google.com/p/diddy/

A few extra Monkey commands (currently for Flash, HTML5 and Android):

* FlushKeys()

* RealMillisecs() - http://www.monkeycoder.co.nz/Community/post.php?topic=471&post=3579

Create the following monkey file:



Create folder called "extras" and the following 3 files:

* extras.android.java
* extras.flash.as
* extras.html5.js

In extras.android.java copy the following:


In extras.flash.as copy the following:


In extras.html5.js copy the following:


Now in your monkey projects you can use the FlushKeys and RealMillisecs commands :)

Feel free to add more targets and more commands - (add to this thread ;))


MikeHart(Posted 2011) [#2]
Thanks, it is very much appreciated.


Wagenheimer(Posted 2011) [#3]
Thanks!!! The XNA port will really need the FlushKeys!


slenkar(Posted 2011) [#4]
thanks


therevills(Posted 2011) [#5]
Ive started a google code project called "diddy" (as in Diddy Kong ;)).

You can download this code from here:

http://code.google.com/p/diddy/downloads/list


therevills(Posted 2011) [#6]
Added RealMillisecs & FlushKeys functions to the other targets.

iOS is not tested... and to get xna to work you need to alter a mojo file:

		// this only works if you change the mojo.xna.cs:
		// public class gxtkApp{
		//        public static gxtkInput input; <---- ADD STATIC KEYWORD HERE (LINE 282 - Monkey V34b)



matty(Posted 2011) [#7]
Is there a way we can modify this code (from mobile tutorials page) so that we can import a module that lets us go to a web address using the browser:

I've played around with trying to import it as a .java module

package com.mamlambo.samples.hellowww;

import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class HelloWorldWideWebActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void launchBrowser(View view) {
        Uri uriUrl = Uri.parse("http://androidbook.blogspot.com/");
        Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
        startActivity(launchBrowser);
    }

    public void searchBrowserGoogle(View view) {
        Intent search = new Intent(Intent.ACTION_WEB_SEARCH);
        search.putExtra(SearchManager.QUERY, "pygmy goats");
        startActivity(search);
    }

}


Also for emailing is it possible to convert this somehow (for Android too)

I'm not all that familiar with how to create modules such as this and don't really understand the terminology "Extern" "static" etc.

http://android-send-message-tutorial-code.googlecode.com/svn/trunk/src/com/mamlambo/tutorial/sendmessage/SendMessageActivity.java


therevills(Posted 2011) [#8]
Maybe try to fully qualify the variables?

Import "extras/extras.${TARGET}.${LANG}"

Extern
	#If TARGET="android" Then
		Function LaunchBrowser:Void() = "extern.launchBrowser"


class extern
{
    static void launchBrowser() {
        android.net.Uri uriUrl = android.net.Uri.parse("http://androidbook.blogspot.com/");
        android.content.Intent launchBrowserActivity = new android.content.Intent(android.content.Intent.ACTION_VIEW, uriUrl);
        MonkeyGame.activity.startActivity(launchBrowserActivity);
    }
}


Not tested ;)


matty(Posted 2011) [#9]
Thanks I will give it a shot and let you know how it goes..


matty(Posted 2011) [#10]
Thanks therevills - works perfectly. I will try and modify it so that it accepts a web address as a parameter.

Next step is to get the email client on the phone to be accessible as well...

Thanks heaps for helping with this.

from Matt

Slight change to allow a user specified address...

Import "extras/extras.${TARGET}.${LANG}"

Extern
	#If TARGET="android" Then
		Function LaunchBrowser:Void(address:String) = "extern.launchBrowser"


class extern
{
    static void launchBrowser(String address) {
        android.net.Uri uriUrl = android.net.Uri.parse(address);
        android.content.Intent launchBrowserActivity = new android.content.Intent(android.content.Intent.ACTION_VIEW, uriUrl);
        MonkeyGame.activity.startActivity(launchBrowserActivity);
    }
}



matty(Posted 2011) [#11]
Thanks again - I've worked out how to send emails too - that can be done like this:

in your "#if TARGET="android" block put this
Function LaunchEmail:Void() = "extern.launchEmail"

in your class "extern" put this:

	static void launchEmail()
	{
		android.content.Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);	
		emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hey! You'll love this new game!");  
		emailIntent.setType("plain/text");  
		emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hey! Try our my game at www.etc....");  
		MonkeyGame.activity.startActivity(emailIntent);
	}



matty(Posted 2011) [#12]
Just a quick simple question - if I change the name of my game so that it does not default to "MonkeyGame" does that mean I will have to change these extern function calls? Or is MonkeyGame used internally only?


therevills(Posted 2011) [#13]
Nope you dont need to change the code, MonkeyGame is only used internally.

You would only have to change it if Mark decides to change it :P


golomp(Posted 2015) [#14]
Thank you a lot Therevills !

Once again you solved a problem i encounter actually with a project.

Golomp