When you join something you're basically copying and pasting the code into that weapon. If you join it to the player you can add extra functions to the player (like player.unstick()) but you can't use stuff like onKeyPressed and onPlayerChats which aren't events of the player.
Your code should look like this (and be in a weapon):
PHP Code:
function onCreated() {
this.join("myclass");
}
//#CLIENTSIDE
function onCreated() {
player.chat = "it works!";
}