Virtual keyboard/gamepad for external use?

0 favourites
  • 4 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Is there a way to trigger a keystroke outside of the construct/browser window when an item is clicked or hovered over?

    Example: I click a sprite on the screen and it produces a keystroke outside of the browser as if I physically hit the key myself.

    Thank you.

  • No, the plugins for keyboard and gamepad does not have any action, but i believe that if you edit the plugins yourself you could add the action to simulate a keystroke

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ok, i have edited the keyboard plugin and here comes a little tutorial:

    First go to the directory: YOUR_CONSTRUCT_DIR\exporters\html5\plugins\keyboard

    then open the files: edittime.js and runtime.js

    basically the first file is where you configure the plugins conditions, actions, etc, the second is where you implement this actions and conditions(some plugins may also need thirdy party plugins, when exporting for cordova you need to install them yourself)

    Configuring the actions

    Well, there is two actions that you need: keydown and keyup, in the first file choose some place and post this code there:

    ////////////////////////////////////////////////////////////
    // Actions
    // AddAction(id,				// any positive integer to uniquely identify this action
    //			 flags,				// (see docs) af_none, af_deprecated
    //			 list_name,			// appears in event wizard list
    //			 category,			// category in event wizard list
    //			 display_str,		// as appears in event sheet - use {0}, {1} for parameters and also <b></b>, <i></i>
    //			 description,		// appears in event wizard dialog when selected
    //			 script_name);		// corresponding runtime function name
    
    AddKeybParam("Key", "Choose a key.  Note that international users and users on different operating systems or devices may not have the same keys available.");
    AddAction(
    	0,
    	af_none,
    	"Simulate keydown",
    	"Keyboard Simulation",
    	"Simulate keydown {0}",
    	"Simulate a keydown from the keyboard",
    	"send_keydown"
    );
    
    AddKeybParam("Key", "Choose a key.  Note that international users and users on different operating systems or devices may not have the same keys available.");
    AddAction(
    	1,
    	af_none,
    	"Simulate keyup",
    	"Keyboard Simulation",
    	"Simulate keyup {0}",
    	"Simulate a keyup from the keyboard",
    	"send_keyup"
    );
    [/code:n12gw647]
    
    Please, read the comments, they will explain the parameters for the AddAction function(the AddKeyParam function i just copied and pasted from the keyboard plugin conditions section(you may want to take a look there))
    
    [b]Implementing the actions[/b]
    Open the second file and find this line:
    
    [code:n12gw647]
    	function Acts() {};
    [/code:n12gw647]
    
    right under it you paste this code:
    
    [code:n12gw647]
    	Acts.prototype.send_keydown = function(key){
    		jQuery.event.trigger({ type : 'keydown', which : key });
    	}
    
    	Acts.prototype.send_keyup = function(key){
    		jQuery.event.trigger({ type : 'keyup', which : key });
    	}
    [/code:n12gw647]
    
    If you know some programming you will understand everything easily.
    
    Now you can save and close the two files, when you open construct2 now the keyboard plugin have the two actions: keyup and keydown under the sections [i]Keyboard Simulation[/i], just use them.
    
    The exact same thing can be done for the gamepad, it may be more complicated because simulate gamepad buttons with javascript may be hard(or no).
  • Ok, i have edited the keyboard plugin and here comes a little tutorial:

    Wow! Thank you! This is very in depth. I will try this out later tonight and see what I come up with.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)