Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Announcements and Showcase
ccbTriggerKeyEvent and ccbTriggerMouseEvent

xanimalkingx
Registered User
Quote
2018-12-14 04:24:05

I found that messing around with _ccbScriptCache got some useful results, such as triggering the keyboard and mouse events of the current behavior.
These only work if the behavior has its onKeyEvent or onMouseEvent prototype functions defined. Also, this wont cause key/mouse events globally (wont cause the events on other scripts/the game itself), it will only cause the event within the behavior its in.

// A method that triggers a key event to happen, despite the user never triggering it themselves
ccbTriggerKeyEvent = function(keycode, pressed, scriptIndex) {
// parameters:
// keycode, pressed, [scriptIndex]
// keycode = The keycode to trigger. Refer to the standard documents of the JavaScript language
// for a list of each key code and what keyboard key each code refers to.
// pressed = Wether to set if the specified key is being pressed down or was pressed but left
// up. Possible values: 0 = down, 1 = up.
// scriptIndex [optional] = The index of the current running script. Should only be 0 unless
// this function fails somehow.

// Optional parameter handler
var scriptIndex = ((arguments.length == 2) || (scriptIndex == null) || (typeof scriptIndex === "undefined") || (typeof scriptIndex !== "number")) ? 0 : scriptIndex;

_ccbScriptCache[scriptIndex]['onKeyEvent'](keycode, pressed);
};

// A method that triggers a mouse event to happen, despite the user never triggering it themselves
ccbTriggerMouseEvent = function(mouseEvtId, wheelDelta, scriptIndex) {
// parameters:
// mouseEvtId, wheelDelta, [scriptIndex]
// mouseEvtId = The mouse event to trigger. Possible values: 0 = move moved, 1 = mouse clicked,
// 2 = left mouse up, 3 = left mouse down, 4 = right mouse up, 5 = right mouse down.
// wheelDelta = The speed of the mouse wheel, if the mouse wheel event id is passed. Negative
// value is mouse wheel backwards, positive value is mouse wheel fowards.
// scriptIndex [optional] = The index of the current running script. Should only be 0 unless
// this function fails somehow.

// Optional parameter handler
var scriptIndex = ((arguments.length == 2) || (scriptIndex == null) || (typeof scriptIndex === "undefined") || (typeof scriptIndex !== "number")) ? 0 : scriptIndex;

_ccbScriptCache[scriptIndex]['onMouseEvent'](mouseEvtId, wheelDelta);
};



Robo
Guest
Quote
2020-08-27 11:54:15

I couldn't get this to work - any more info on where this code should sit exactly.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internation?l" (you are not logged in)


Text:

 

  

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