ハテナキハテナ --unics’s think/sync

福井のまんなかでぼんにょり呟く、ゆにくすの日々オボエガキなど。

C#で現在指定キーが押されているか判別する方法。

using System.Runtime.InteropServices;

public class Hogehoge
{
    [DllImport("user32")] static extern short GetAsyncKeyState(Keys vKey);
    public Hogehoge()
    {
        // コンストラクタ
    }
    public void IsPressCtrlKey()
    {
        if( GetAsyncKeyState( Keys.ControlKey ) < 0 )
        {
            // コントロールキーが押されている場合の処理
        }
    }
}

こんな感じ。APIなのでVBとかVCでもいけると思うデス。詳細はメソッド名でググればわさわさ出てくるハズ。
ていうか別にコンストラクタまで書かんでもいいやん自分…(苦笑)。

qqq for your reading!!
(c)Electro-U-nics --since 2004.03.26