LoginSignup
0
0

More than 3 years have passed since last update.

Unityから一定間隔でスクリーンショットボタンを押す

Last updated at Posted at 2019-10-23

動機

VRChatで表情認識をしたい(願望):1日目
https://qiita.com/hohoemi108yen/items/df21c1c31c1bfd105851

上の記事のための学習として、UnityからWindowsのキー入力を扱う方法を調べたかった。

注意点

Unityには「System.Windows.Forms」は標準では導入されていないので、
下記パスからdllファイルをAssetフォルダ下にコピーする必要があった。

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll

ソースコード

AutoScreenshot.cs
using UnityEngine;
using System.Windows.Forms;


public class AutoScreenshot : MonoBehaviour
{
    //撮影周期(秒)
    const int PERIOD_SECOND = 500;
    int count;
    void Start()
    {
        count = PERIOD_SECOND;
    }

    void Update()
    {
        if (count == 0)
        {
            SendKeys.SendWait("%{PRTSC}");
            Debug.Log("スクショを撮影しました");

            count = PERIOD_SECOND;
        }
        Debug.Log(count--);

    }
}

参考

アクティブウインドウのスクリーンショットを周期的に撮るだけ
http://shirakamisauto.hatenablog.com/entry/2015/05/21/163421

Unityから他アプリを操作する方法
https://qiita.com/nise_aoi/items/7572a7024f941700add0

【C#】キーエミュレート送信のまとめ【覚書メモ】
http://edutainment-fun.com/hidemaru/microsoft/キーエミュレート送信のまとめ【c】【覚書メモ】_2535.html

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0