模拟键盘按钮按箭头键

时间:2018-11-14 21:03:18

标签: c++ winapi sendinput

我已经设置了2个模拟键盘按钮按下的功能

# set maximum number of processes to run in SLURM
MAX_QUEUE=200

Protein_sequence='MNNAANTGTTNESNVSDAPRIEPLPSLNDDDIEKILQPNDIFTTDRTDASTTSSTAIEDIINPSLDPQSAASPVPSSSFFHDSRKPSTSTHLVRRGTPLGIYQTNLYGHNSRENTNPNSTLLSSKLLAHPPVPYGQNPDLLQHAVYRAQPSSGTTNAQPRQTTRRYQSHKSRPAFVNKLWSMLNDDSNTKLIQWAEDGKSFIVTNREEFVHQILPKYFKHSNFASFVRQLNMYGWHKVQDVKSGSIQSSSDDKWQFENENFIRGREDLLEKIIRQKGSSNNHNSPSGNGNPANGSNIPLDNAAGSNNSNNNISSSNSFFNNGHLLQGKTLRLMNEANLGDKNDVTAILGELEQIKYNQIAISKDLLRINKDNELLWQENMMARERHRTQQQALEKMFRFLTSIVPHLDPKMIMDGLGDPKVNNEKLNSANNIGLNRDNTGTIDELKSNDSFINDDRNSFTNATTNARNNMSPNNDDNSIDTASTNTTNRKKNIDENIKNNNDIINDIIFNTNLANNLSNYNSNNNAGSPIRPYKQRYLLKNRANSSTSSENPSLTPFDIESNNDRKISEIPFDDEEEEETDFRPFTSRDPNNQTSENTFDPNRFTMLSDDDLKKDSHTNDNKHNESDLFWDNVHRNIDEQDARLQNLENMVHILSPGYPNKSFNNKTSSTNTNSNMESAVNVNSPGFNLQDYLTGESNSPNSVHSVPSNGSGSTPLPMPNDNDTEHASTSVNQGENGSGLTPFLTVDDHTLNDNNTSEGSTRVSPDIKFSATENTKVSDNLPSFNDHSYSTQADTAPENAKKRFVEEIPEPAIVEIQDPTEYNDHRLPKRAKK'

# 5' primer to add at "N" terminal (left of the sequence)
p5=${Protein_Sequence:463:30}

header=true # file has header and I have to skip it

# open file containing the sequence fused at the right of p5
for insert in `cat $1 | awk 'BEGIN{FS=","}{print $2}'`
do
    # if header, then continue with next iteration and flag header as false
    if [ $header = true ]
    then
        header=false
    else
        printf ">${insert}\n${p5}${insert}" > ${insert}.fasta # write fasta file (this is the input of psipred)

        # check how many processes are in the queue
        queue=$(squeue -u aerijman | wc -l)
        queue=$(echo $queue -1 | bc)

        # if few processes queued, proceed, else wait.
        if [ $queue -lt $MAX_QUEUE ]
        then
            sbatch -p campus -c 1 --job-name=${insert} --wrap="runpsipred ${insert}.fasta"
        else
            # take the chance to find *horiz files which contain the result
            for prefix in `ls *horiz`
            do
                # extract the resulting sequence of 2ry structure elements and append it to a ingle file with all esults
                horiz=$(while read line; do if [ "${line:0:4}" == Pred ]; then echo ${line:6:${#line}} | tr -d "\n"; fi; done < $prefix)
                printf ">${p5}${insert}\n${horiz}" >> horiz.results
                # rm all side files (from psipred-blast)
                rm ${prefix:0:-5}*
            done

            # This  loop is tracking if any process has finished (so a new processes can ve queued)
            while [ $queue -ge $MAX_QUEUE ]
            do
                queue=$(squeue -u aerijman | wc -l)
                queue=$(echo $queue -1 | bc)

            done
        fi
    fi
done

在大多数情况下都可以使用,但是作为简单示例,在模拟箭头键时它在某些应用程序中会失败

void KeyboardButtonDown(DWORD a)
{
    INPUT Input = { 0 };
    // Set up a generic keyboard event.
    Input.type    = INPUT_KEYBOARD;
    Input.ki.wVk  = a; 
    SendInput(1, &Input, sizeof(INPUT));
}

void KeyboardButtonUp(DWORD a)
{
    INPUT Input = { 0 };
    Input.type        = INPUT_KEYBOARD;
    Input.ki.dwFlags  = KEYEVENTF_KEYUP;
    Input.ki.wVk      = a;
    SendInput(1, &Input, sizeof(INPUT));
}

它可以在记事本中使用,但是在玩游戏时却什么也没做。我已经将游戏中的控件映射为使用其他键,然后它可以正常工作。

我在这里做什么错了?

1 个答案:

答案 0 :(得分:2)

如果接收应用程序使用直接输入,则必须发送扫描代码而不是虚拟键代码。