Page 1 of 1

Can I use keypresses from players?

Posted: 05 October 2020, 23:27
by GoDodyGo
In addition to mouse clicks (or tablet finger-pointing), can I connect up keypresses to UI events?

Code: Select all

// This works
dojo.connect( this.playerHand,  'onChangeSelection', this, 'onPlayerHandSelectionChanged' );

// I would like to also have this:
dojo.connect( this.playerHand, 'onkeypress', this, 'onPlayerHandKeypress' );
In my card game, after a player selects 1 card, the player might want to discard it, or they might want to put it in a different location in their hand (e.g. to group up like-cards).

Now I show buttons for SORT and DISCARD and force them to click. How can I add keyboard shortcuts "S" and "D" so that after they use the mouse to select a card, when they press D then the card is discarded?

I've looked at some other games but do not see this capability. Also when I type, the chat window opens automatically. It would be OK for my game to show a toggle ALLOW KEYBOARD SHORTCUTS ON/OFF or similar to allow interested players to do this, and I would filter the keypresses or send them through to chat.

Any ideas? Thanks!

Re: Can I use keypresses from players?

Posted: 06 October 2020, 07:23
by Draasill
I was thinking about this for the coinche too :)

But I didn't reach a conclusion as it's a good idea or not.

Re: Can I use keypresses from players?

Posted: 06 October 2020, 13:38
by Tisaac
I've posted about it a few days ago about Concept on the discord server, here is how I did to bypass the chat automatic opening :

Code: Select all

 dojo.connect(document, 'onkeydown', (evt) => {
        if(!$("concept-guess")) return;

        if(this.game.chatbarWindows['table_' + this.table_id].status == 'expanded') return;
        this.game.collapseChatWindow('table_' + this.table_id);
        evt.stopPropagation();
	// do whatever you need with evt.keyCode
 });