Multiple key click code problem

Hi guys,
I’m making a 2d sprite based game myself and I bumped into a problem.
As example, let’s say I’ve coded keys J to attack and K to block.
I’d like to do something like casting spell or sth else after pressing both of the keys at the same time.
I’ve read plenty of tutorials of this but nothing worked. The problem is, when I do press both keys, the character is either attacking or blocking because the key J or K was actually pressed first. I’ve tried using getKeyDown // making delay before [attack animation and code execution] to check if another key was pressed meanwhile // using Coroutine to make delay before executing code to check if both keys were pressed.
Yet nothing worked for me, I’d like you guys to give me some tips
Greets

@tisseq You can go two ways with this. One way is wait before doing the single button keys.

Here’s some pseudocode:

//Input phase
if (keyDown(attackKey))
{
    isAttackPressed = true;
    timeAttackPressed = Time.time;
} else if (keyUp(attackKey))
{
    isAttackPressed = false;
}

if (keyDown(blockKey))
{
    isBlockPressed = true;
    blockAttackPressed = Time.time;
} else if (keyUp(blockKey))
{
    isBlockPressed = false;
}

//Handling input phase
if (state == idle)
{
    if (isAttackPressed && isBlockPressed)
    {
        //do something
    } else
    if (isAttackPressed && Time.time - timeAttackPressed < keyPressThreshold) //e.g. 0.1f
    {
        //do attack
    } else
    if (isBlockPressed && Time.time - timeAttackPressed < keyPressThreshold) //e.g. 0.1f
    {
        //do block
    }
}

The other way is to start the attack or block states immediately, but have a time threshold where you can switch the state to the spell state, but then animations might need to be stopped etc. Here’s some other pseudocode:

if (isAttackPressed && isBlockPressed && Time.time - lastActionTime < keyPressThreshold)
{
    //do something
} else
if (state == idle)
{
    if (isAttackPressed && isBlockPressed) //just in case they were pressed together
    {
        //do something
    }
    if (isAttackPressed)
    {
        lastActionTime = Time.time;
        //do attack
    } else
    if (isBlockPressed)
    {
        lastActionTime = Time.time;
        //do block
    }
}

thanks @xenonmiii ,
gonna test and let you know if it worked