Help with my script, please !!

Subscribe to Help with my script, please !! 11 posts, 3 voices

 
Tolke Scriptwright

* First of all, sorry if i have some grammar errors, i am not an english speaker *

Well, i am trying to do my first script. The idea is simple. I want to have some hot keys for my forum phpbb 2.x

I got the basis of it, i mean, i need an "addEventListener" that trigger when a key is press, and then some "if" whith my combinations keys.

As i've been looking trying to write at the text area of my forum, it will be complicated, but i will do it.

The problem i have now, that the next code, does not work, and i do not know why. Some charity soul can help me?

The code:

function Tecla (e) {

if(e.charCode == 99) { //if the key press is "c"
alert("The key c is press");
}
}

window.addEventListener('onkeypress', Tecla, false);

//--- End Code ---

Well the page that the script is loaded is */posting.php*, i mean: @include */posting.php*

As i said before, when i press letter "c" on my keyboard, it happens nothing. I've been hours looking about it on google, and nothing, you are my last hope!

If someone can teach me in what i am wrong, i would apreciate very much.

Thank you everyone!

 
VIPPER Scriptwright

Change onkeypress to keypress

 
JoeSimmons Scriptwright

Change onkeypress to keypress

Yup. When you use addEventListener, you don't ever use 'on'. You would use keypress, click, keyup, keydown, etc without the 'on'. Although on an onClick or OnKeyPress you would use it.
Best to use keyup, keypress seems to not work for me.
Look at this script for more info.

 
Tolke Scriptwright

Oh thanks !!!, i will try it

Edit:

Well your little scritp works Joe Simmons, but i have found a little bug, i mean, you have to press Ctrl + Alt + a letter (b,h,u,i), well, the bug i've found was that first mozilla must show its own shorcut before your little script works. I explain:

In mozilla the short cut Ctrl + h, show de window Navigation History (it show all the webpages that you have visited in days), so first i must press Ctrl + h, before Ctrl + Alt + h, works.

Maybe i am doing something wrong, if it is so, can you tell me, why?

Again, Thanks for the help.

P.D.
Sorry for my badspelling.

 
JoeSimmons Scriptwright

I made it so you have to press ctrl and alt with the letter so you don't accidentally do a command while typing.

 
Tolke Scriptwright

Ye, i understood, but i have to do a command before the ctrl + alt + letter works, is annoying, but not problematic.

Other question, how can i use a function defined in other file? The problem is i have to use the function called "bbfontstyle(var1,var2)" defined in the file posting.php.

That is the function i need to "write" in my forum when i press a shortcut. How can i do that?

Again, many thanks for the help !!

 
JoeSimmons Scriptwright

Just change the e.ctrlKey && e.altKey to e.shiftKey so it will run when you press shift+u for example.

 
Tolke Scriptwright

Oh, it's work, but what about, the second question?

Exactly this question:

how can i use a function defined in other file? The problem is i have to use the function called "bbfontstyle(var1,var2)" defined in the file posting.php.

That is the function i need to "write" in my forum when i press a shortcut. How can i do that?

Thanks for the help !

 
JoeSimmons Scriptwright

unsafeWindow.bbfontstyle(var1,var2);

 
Tolke Scriptwright

Oh, that's great, i finished it, yeah.

Now i look at it, and it is a really easy code, jajaja, but when you don't know, it cost you a lot, no?, jajaja

Well, i'm document it, and finally i can publish. jeje

Really, Many Thanks for the help !!!

Here it is the script.

Really, Thanks for all the help !!!

 
JoeSimmons Scriptwright

Eres bienvenida