≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
how to check key press once
Posted by:
(you are not logged in)
Enter the missing letter in: "?nternational"
(you are not logged in)
Text:
[quote][b][/b] wrote: This script will: Call action ONLY ONE TIME if key pressed down... (no matter if key is held down) AND if relased it calls action ONLY ONE TIME. (no matter if key left up forever) If i still misunderstood your question then i hope somebody can answer it for you. [code]/* <behavior jsname="behavior_IF_KEY_PRESSED" description="IF_KEY_PRESSED"> <property name="Keycode" type="int" default="13" /> <property name="Actied" type="action"/> <property name="ActionKeyRelased" type="action"/> </behavior> */ key_p = [250]; for(var i=0; i<250; ++i) key_p.push(0); key_l = [250]; for(var i=0; i<250; ++i) key_l.push(0); key_lu = [250]; for(var i=0; i<250; ++i) key_lu.push(2); ccbRegisterKeyDownEvent("keyPressedDown"); function keyPressedDown(keyCode) { key_p[keyCode]=1; //print("pressed key KEYCODE" +keyCode); } ccbRegisterKeyUpEvent("keyPressedUp"); function keyPressedUp(keyCode) { key_p[keyCode]=0; key_l[keyCode] =0; key_lu[keyCode] =0; } behavior_IF_KEY_PRESSED = function() { }; behavior_IF_KEY_PRESSED.prototype.onAnimate = function() { //IF KEY PRESSED DOWN :EXECUTE ACTION ONLY ONCE.. if (key_p[this.Keycode] == 1 && key_l[this.Keycode] == 0) { key_l[this.Keycode] =1; ccbInvokeAction(this.Actied); print(this.Keycode +"pressed"); } //IF KEY RELASED :EXECUTE ACTION ONLY ONCE.. if (key_p[this.Keycode] == 0 && key_lu[this.Keycode] == 0) { key_lu[this.Keycode] =1; ccbInvokeAction(this.ActionKeyRelased); print(this.Keycode +"relased"); } return true; } [/code][/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact