Help us understand the problem. What is going on with this article?

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

動機

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away