LoginSignup
0
1

More than 5 years have passed since last update.

C++ Builder XE4 > YouTube repeater > 固定秒(10)巻き戻し * 無限ループ

Last updated at Posted at 2018-04-26
動作環境
C++ Builder XE4
秀丸エディタ Version 8.79

処理概要

  • チェックボックスON時、リピーター機能ON
  • リピート時間(秒): 10秒 (Jキーの巻き戻し時間)

YouTube上の語学動画の特定のフレーズをしばらく繰返したいときに使う。

例:

我介绍一下 (I introduce)

参考

FindWindowEx()してからGetWindow()する。

コード

Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE で管理されるコンポーネント
    TButton *B_repeat;
    TCheckBox *CHK_repeat;
    TTimer *TIMinterval;
    void __fastcall B_repeatClick(TObject *Sender);
    void __fastcall CHK_repeatClick(TObject *Sender);
    void __fastcall TIMintervalTimer(TObject *Sender);
private:    // ユーザー宣言
    void __fastcall repeatChrome(void);
public:     // ユーザー宣言
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::B_repeatClick(TObject *Sender)
{
    repeatChrome();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::repeatChrome(void)
{
    STARTUPINFO si = {};
    si.cb = sizeof(si);
    PROCESS_INFORMATION pi = {};

    CreateProcess(NULL, L"Chrome.exe", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);

    WaitForInputIdle(pi.hProcess, INFINITE);
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);

    HWND chromeWindow = GetDesktopWindow();
    chromeWindow = FindWindowEx(chromeWindow, NULL, L"Chrome_WidgetWin_1", NULL);
    HWND chrome = GetWindow(chromeWindow, GW_HWNDNEXT);

    SetForegroundWindow(chrome);
    keybd_event('J', 0, 0, 0);
}
void __fastcall TForm1::CHK_repeatClick(TObject *Sender)
{
    if (CHK_repeat->Checked) {
        repeatChrome(); // この時点で巻き戻し
        TIMinterval->Interval = 10 * 1000; // msec (jコマンドの巻き戻しは10秒)
        TIMinterval->Enabled = true;
    } else {
        TIMinterval->Enabled = false;
    }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::TIMintervalTimer(TObject *Sender)
{
    repeatChrome();
}
//---------------------------------------------------------------------------

実行手順

  1. Chromeを起動してYouTubeで語学動画を再生する
  2. YouTube repeater を起動する
  3. 繰返したいタイミングでYouTube repeater 上の「Repeat」チェックボックスをONにする

以後、その部分の動画が延々と再生される。

qiita.png

Repeatボタンはテスト用で実運用では使わない。

注意

YouTube repeater を起動してRepeatチェックボックスONにしている限りChromeに「j」という入力が続く。

ChromeでQiita記事を書くなどしていると、そこに「j」という謎のメッセージが記載され続ける。

語学ツール

0
1
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
1