MAGDX
MAGDX

Reputation: 3

How can I trigger a keydown event from code in JavaScript?

I tried to put down a shape of Tetris with setInterval, and I had a function implemented that with keydown pressed, if it can, the shape will bi down 1 block, but I want do that every second... So, how can I trigger a keydown event in code to reuse my function?

Thanks and sorry for my english!

Arkaitz

Upvotes: 0

Views: 71

Answers (1)

Suman Lama
Suman Lama

Reputation: 946

Some thing like this should work.

    var newEvent = $.Event('keydown', {
        keyCode: event.keyCode
    });
    newEvent.keyCode = $.ui.keyCode.DOWN;
    $(this).trigger(newEvent);

Upvotes: 1

Related Questions