You are not logged in.

#1 2005-08-26 12:52:41

totomds
Member
Registered: 2005-08-26
Posts: 1

Catch onkeypress event?

Hello,

Could someone humour me (the answer is probably very easy but I haven't figured it out yet) and help me figure out how to catch the "enter" key when it is pressed inside of a tiny mce text area? I am trying to write a chat client and this would come in very useful.

Thank you,
Mitchel

Offline

 

#2 2005-11-10 18:43:26

Vish
Member
Registered: 2005-11-09
Posts: 26

Re: Catch onkeypress event?

I would like to know this too...

Offline

 

#3 2005-11-10 19:03:41

spocke
Administrator
From: Sweden, Skellefteċ
Registered: 2004-11-25
Posts: 9997
Website

Re: Catch onkeypress event?

Something like: tinyMCE.addEvent(tinyMCE.getInstanceById('<element>').getDoc(),"onkeydown",yourEventHandler); should work.

And

function yourEventHandler(e) {
  e = window.event ? window.event : e;

  if (e.keyCode == 13)
    doSomeFunkyStuff();
}

Notice, this is not tested at all. You may need to modify things here and there.


Best regards,
Spocke - Main developer of TinyMCE

Offline

 

#4 2005-12-02 03:08:27

Vish
Member
Registered: 2005-11-09
Posts: 26

Re: Catch onkeypress event?

If using advance theme, where exactly these two pieces of code should go?
Thanks

Offline

 

#5 2006-01-02 23:16:45

jareda
Member
Registered: 2006-01-02
Posts: 4

Re: Catch onkeypress event?

Offline

 

#6 2006-01-03 00:10:20

Afraithe
Administrator
From: Skellefteċ, Sweden
Registered: 2005-01-03
Posts: 1930
Website

Re: Catch onkeypress event?

Please note that attaching events on keypress or "common" events can affect performance quite a lot.


Afraithe
TinyMCE Developer
Moxiecode Systems

Offline

 

#7 2006-06-11 16:25:58

CђrΐsτσρhΞr ScЋδlτξη
Member
From: Hong Kong
Registered: 2006-04-25
Posts: 10
Website

Re: Catch onkeypress event?

Seems to work with the following:

Code:

tinyMCE.addEvent(tinyMCE.getInstanceById('<element>').getDoc(),"keydown",yourEventHandler);

(Note "onkeydown" becomes "keydown")

Offline

 

#8 2007-03-22 18:27:17

tjstalcup
Member
Registered: 2007-03-22
Posts: 2

Re: Catch onkeypress event?

This doesn't work

Offline

 

#9 2007-12-25 11:36:16

dekker
Member
Registered: 2007-10-08
Posts: 47

Re: Catch onkeypress event?

Where do I need to post this eventhandler?

Offline

 

#10 2007-12-27 04:43:36

huiyixm
Member
Registered: 2007-12-27
Posts: 1

Re: Catch onkeypress event?

Unveil the SEO/SEM tips and technologies toward Baidu, Google in China. As well as those toward Google and Yahoo in the world.
Search Engine Marketing Coference and Expo comes to xiamen with it bilingual Search Expo event.Search Expo is a two-days event, which will unveil the chinese search marketing tips and strategies as well as the English.The conference will focus on both organic and paid search. Sessions will be presented by both chinese search expert and international expert. A discussion panel regarding the search strategies for Olympic 2008 will cover the hotest topic and industry.   Search Engine Marketing Conference & Expo,xiamen china ,apri 2008。
Contact US:http://event.timev.com/en/

Offline

 

#11 2008-01-13 18:24:58

manchumahara
Member
Registered: 2008-01-08
Posts: 12

Re: Catch onkeypress event?

spocke wrote:

Something like: tinyMCE.addEvent(tinyMCE.getInstanceById('<element>').getDoc(),"onkeydown",yourEventHandler); should work.

And

function yourEventHandler(e) {
  e = window.event ? window.event : e;

  if (e.keyCode == 13)
    doSomeFunkyStuff();
}

Notice, this is not tested at all. You may need to modify things here and there.

Please help me if u are free:
In my plugin I wrote the bellow code for event handler:

What I want to do is map unicode char for my local language that is like if i press v then it will show the unicode char  that is mapped for v. According to my code I am getting

<unicode char>v   but i want that it will be only <unicode char> and no v.

Any help ?

    handleEvent : function(e) {   
            switch (e.type) {
                    case "keypress":               
                        return false;
                    case "keydown":
                //test check for char 'v'   
                        if(e.keyCode=="86"){
                            tinyMCE.execCommand('mceInsertContent', false, '\u09AD'); //v
                        }
                                return false;               
                    case "keyup":                   
                            return false;
                }
        return true;
    },

Offline

 

#12 2008-01-13 18:52:28

Felix Riesterer
Administrator
From: Germany
Registered: 2005-12-30
Posts: 3901
Website

Re: Catch onkeypress event?

manchumahara wrote:

In my plugin I wrote the bellow code for event handler

This cannot work in TinyMCE 3.x!

Spocke's answer is from November 2005 so it doesn't refer to the actual release candidate but to some 2.x version of TinyMCE.

For TinyMCE version 3.x you'll need something like this:

Code:

tinyMCE.init({
    mode : ...,
    ...,
    setup : function (ed) {
        ed.onKeyPress.add(
            function (ed, evt) {
                alert("Editor-ID: "+ed.id+"\nEvent: "+evt);
                // Do some great things here...
            }
        );
    },
    ...
});

Greetings from Germany,

Felix Riesterer.


Greetings from Germany,

Felix Riesterer.
(-> about me and this forum <-)

Offline

 

#13 2008-01-13 19:47:43

manchumahara
Member
Registered: 2008-01-08
Posts: 12

Re: Catch onkeypress event?

Felix Riesterer wrote:

manchumahara wrote:

In my plugin I wrote the bellow code for event handler

This cannot work in TinyMCE 3.x!

Spocke's answer is from November 2005 so it doesn't refer to the actual release candidate but to some 2.x version of TinyMCE.

For TinyMCE version 3.x you'll need something like this:

Code:

tinyMCE.init({
    mode : ...,
    ...,
    setup : function (ed) {
        ed.onKeyPress.add(
            function (ed, evt) {
                alert("Editor-ID: "+ed.id+"\nEvent: "+evt);
                // Do some great things here...
            }
        );
    },
    ...
});

Greetings from Germany,

Felix Riesterer.

thank you  for your reply. i have seen many topic related to this  but much replies there. Yah I am using version 2.x as version3 is not final yet. According to my first post in this topic I want to handle this from a plugin. and plz help me how can i solve this. I want cancel the keydown or keypres event and want to insert char what i want according to may mapping.

This is my full plugin code :

Code:

/* Import plugin specific language pack */
tinyMCE.importPluginLanguagePack('banglafkb', 'en');
<script language="javascript" type="text/javascript" src="jscripts/test.js"></script>
var TinyMCE_KeywordPlugin = {
    getInfo : function() {
        return {
            longname  : 'Bangla Web based keyboard for tinyMCE',
            author    : 'Sabuj Kundu',
            authorurl : 'http://manchu.wordpress.com',
            infourl   : 'yet to add',
            version   : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
        };
    },

    getControlHTML : function(cn) {
        switch (cn) {
            case "banglafkb":
                var html = '<select id="{$editor_id}_bnkeyboardSelect" name="{$editor_id}_bnkeyboardSelect" onfocus="tinyMCE.addSelectAccessibility(event, this, window);" onchange="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'bnKeyboardSelect\',false,this.options[this.selectedIndex].value); this.selectedIndex=0;" class="mceSelectList"><option value="">{$lang_banglafkb_keyboard_default}</option>';
html +='<option value="bnenglish">{$lang_banglafkb_keyboard_english}</option>';
html +='<option value="bnphonetic">{$lang_banglafkb_keyboard_phonetic}</option>';
html +='<option value="bnunijoy">{$lang_banglafkb_keyboard_unijoy}</option>';
html +='<option value="bnprobhat">{$lang_banglafkb_keyboard_probhat}</option>';
html +='<option value="bninscript">{$lang_banglafkb_keybaord_inscript}</option>';
                html += '</select>';
                return html;
        }

        return "";
    },
    /*
    In Netscape 4 the keydown event fires only once, when the user initially depresses the key. 
    In all     other browsers there is no difference between keydown and keypress.
    */
    handleEvent : function(e) {    
            switch (e.type) {
                    case "keypress":                
                        return false; 
                    case "keydown":
                //test check for char 'v'    
                        if(e.keyCode=="86"){
                            tinyMCE.execCommand('mceInsertContent', false, '\u09AD'); //v
                        }
                                return false;               
                    case "keyup":                    
                            return false;
                }
        return true;
    },    
    execCommand : function(editor_id, element, command, user_interface, value) {
        // Handle commands
        switch (command) {
            case "bnKeyboardSelect":  
                switch(value){
                    case "bnenglish":
                        alert("English keyboard layout is activated");
                        return true;
                    case "bnphonetic":                        
                        alert("Phonetic keyboard layout is activated");
                        return true;
                    case "bnunijoy":
                        alert("Unijoy keyboard layout is activated");
                        return true;
                    case "bnprobhat":
                        alert("Probhat keyboard layout is activated");
                        return true;
                    case "bninscript":
                        alert("Inscript keyboard layout is activated");
                        return true;
                }//end inner switch
                
                //tinyMCE.execInstanceCommand (editor_id, 'mceInsertContent', false, value);
                return true;
        }

        // Pass to next handler in chainI am
        return false;
    },
    /*    
    function _parsePhonetic(){
            var e = (window.event) ? event.keyCode : evnt.which; // get the keycode
            alert(String.fromCharCode(e));
            return true;
    },
    */
    handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
    }
};

tinyMCE.addPlugin("banglafkb", TinyMCE_KeywordPlugin);

I want to adop a  some keyboard layout to write in local language as well as in english too..

I am greatly in need of it. plz if any one can plz help me.

Last edited by manchumahara (2008-01-13 20:05:19)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2008 PunBB