Light Blue Pointer
본문 바로가기
Developing/Journal

크롬에서 백그라운드에 재생되고있는 미디어 뒤로 감기, 앞으로 감기, 정지/재생하기

by Greedy 2023. 11. 10.

따라하기 귀찮으신 분은 이거 다운받아서 실행하기!

왼쪽 방향키 : 되감기 ,아래 방향키 : 멈추기 ,오른쪽 방향키 : 뒤로 감기

rewind_chrome.exe
0.69MB

따라야 할 6단계 스텝

1. autohotkey 설치

 

https://www.autohotkey.com/

 

AutoHotkey

AutoHotkey provides a simple, flexible syntax allowing you to focus more on the task at hand rather than every single little technicality. It supports not only the popular imperative-procedural paradigm, but also object-oriented and command-based programmi

www.autohotkey.com

2. 아래의 스크립트를 메모장에 입력하고 .ahk 로 저장

크롬에서 동작하는

<- : rewind, 아래 화살표 : pause/stop , -> : fast forward 임 

다른 프로그램, 다른 키로 커스텀하고 싶으면 아래의 더 자세한 이야기를 읽을 것 !

#SingleInstance Force
#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir%  

#InstallKeybdHook

; YOUTUBE (Microsoft-Edge)-another program FOCUS CHANGE: --------------------------------------

Down::VideoPause("ahk_exe chrome.exe");use program name

VideoPause(title)
{
	
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Space}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}

Left::VideoRewind("ahk_exe chrome.exe")

VideoRewind(title)
{
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Left}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}

Right::VideoForwind("ahk_exe chrome.exe")

VideoForwind(title)
{
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Right}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}

 

키가 간혹 안 먹힐때가 있는데 그러면 sleep을 10쯤으로 늘려주면 됨

3. AutohotkeyDash 실행, Compile -> Source(Script file) 아까 저장한 .ahk 파일 불러옴

4. 원하는 위치를 Destination에 설정, 원하는 이름의 exe로 저장

5. Convert 누르면 exe파일 만들어짐

6. 폴더에 가서 .exe 파일 눌러서 쓴다!

실행 잘 됨

더 자세한 이야기

인강 들으면서 코딩하는데 타이핑하다가 뒤로가기로 뒤로 감고싶었음

투컴을 쓸때는 한쪽에 인강 틀고 키보드2의 방향키로 신나게 감고 스페이스바로 재생/정지 하면서 편리하게 듣고 있었는데

로지텍 플로우 연결이 자꾸 끊어져서 너무 불편하여 한개의 컴에서 인강까지 듣게 되었음

 

그런데 문제 발생 : 

그러려면 마우스로 재생되고있는 탭을 클릭하고 나서 방향키를 눌러서 감아줘야 했음

투컴 쓸때처럼 그냥 노션/블로그/인텔리제이에 타이핑하고 있는 상태에서 방향키 팍팍! 눌러서 감기가 안되는게 너무너무 불편했음

 

"how to fast forward when not focused" 로 검색했는데 

유튜브를 틀어놓고 옵시디언을 하다가 유튜브 뒤로가기 앞으로가기를 하고싶은 사람이 올린 코드를 발견!

글을 읽다가 AutoHotKey라는걸 알게 됨

https://superuser.com/questions/1477902/how-to-rewind-youtube-when-not-focused

 

How to rewind youtube when not focused

The context: Sometimes I am playing a fullscreen game on one monitor while watching a video on the other. Oftentimes the game I play has no "fullscreen window" mode. (right now I'm playing one tha...

superuser.com

https://forum.obsidian.md/t/autohotkey-script-for-controlling-youtube-media-without-losing-focus-on-obsidian/55435

 

Autohotkey Script for controlling Youtube media without losing focus on Obsidian

HI. If you take notes in Obsidian while watching Youtube videos in a browser, this AutoHotKey script will allow you to rewind, pause, or fast forward the video without taking your hands off your keyboard, as the focus automatically returns to Obsidian. (Th

forum.obsidian.md

그리고 옵시디언이라는 걸 하는 와중에 유튜브 뒤로감기 하는 사람을 발견!

저 코드를 받고 코드 좀 수정하고 내가 필요로 하는 키는 j,k,l이 아니라

left arrow, right arrow, space라서 구글링 시작함

공식 docs가 잘 정리되어있어서 기능 서치하기 편리했음!

 

https://www.autohotkey.com/docs/v1/KeyList.htm

 

List of Keys (Keyboard, Mouse and Controller) | AutoHotkey v1

VKnn Specify for nn the hexadecimal virtual key code of a key. This rarely-used method also prevents certain types of hotkeys from requiring the keyboard hook. For example, the following hotkey does not use the keyboard hook, but as a side-effect it is tri

www.autohotkey.com

처음에는 이 키 리스트를 보고 {} 없이 개발하기 시작했는데 하나도 안 먹혔음

 

https://www.autohotkey.com/docs/v1/lib/IfWinExist.htm

 

IfWinExist / IfWinNotExist - Syntax & Usage | AutoHotkey v1

Checks if the specified window exists. Deprecated: These control flow statements are not recommended for use in new scripts. Use the WinExist function instead. If either of these control flow statements determines that a qualified window exists, the Last F

www.autohotkey.com

이 문서 보고 

IfWinExist, Untitled - Notepad
{
    WinActivate ; Use the window found by IfWinExist.
    WinMaximize ; Same as above.
    Send, Some text.{Enter}
    return
}

중간에 {Enter}있길래 저거보고 중괄호 치기 시작하고 성공

 

 

최종 스크립트 -> 마이크로소프트 엣지용

#SingleInstance Force
#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir%  

#InstallKeybdHook

; YOUTUBE (Microsoft-Edge)-another program FOCUS CHANGE: --------------------------------------


Down::VideoPause("ahk_exe msedge.exe")

VideoPause(title)
{
	
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Space}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}



Left::VideoRewind("ahk_exe msedge.exe")

VideoRewind(title)
{
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Left}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}




Right::VideoForwind("ahk_exe msedge.exe")

VideoForwind(title)
{
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Right}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}

 

 

최종 스크립트 -> 크롬용

#SingleInstance Force
#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir%  

#InstallKeybdHook

; YOUTUBE (Microsoft-Edge)-another program FOCUS CHANGE: --------------------------------------

Down::VideoPause("ahk_exe chrome.exe")

VideoPause(title)
{
	
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Space}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}

Left::VideoRewind("ahk_exe chrome.exe")

VideoRewind(title)
{
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Left}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}

Right::VideoForwind("ahk_exe chrome.exe")

VideoForwind(title)
{
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Right}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}

 

약간의 추가 설명 :

프로그램이 동작하지 않으면 멈추거나 리와인드하도록 설정되어있는 프로그램을 한번 클릭해주고 다른 프로그램 클릭해주면 잘 돌아감

 

Left::VideoRewind("ahk_exe chrome.exe") -> 백그라운드에 있는데 조작하고 싶은 프로그램을 chrome.exe 대신에 넣어주면 됨

 

눌러서 조작하고 싶은 키를 여기다 넣을것

Left::VideoRewind("ahk_exechrome.exe")

 

프로그램에 전달하고 싶은 키를 여기다 넣을것

sleep 1
Send {Right}
sleep 1

 

끝!

엣지에 틀어놓은 강의 hotkey로 조작하고 구글링이랑 노션/블로그는 크롬에서 쓰는 중임

예전보다 편하다...

쓰다보니 생각보다 코딩할때 위아래 방향키랑 옆 방향키 많이 써서 불편해서

ctrl+left등으로 ctrl도 같이 눌러야되게 바꿨다

#SingleInstance Force
#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir%  

#InstallKeybdHook

; YOUTUBE (Microsoft-Edge)-another program FOCUS CHANGE: --------------------------------------

^Left::VideoRewind("ahk_exe msedge.exe")
^Right::VideoForwind("ahk_exe msedge.exe")
^Down::VideoPauseAndPlay("ahk_exe msedge.exe")

VideoRewind(title)
{
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Left}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}

VideoPauseAndPlay(title)
{
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Space}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}

VideoForwind(title)
{
	WinGetActiveTitle, CurrentWin
	IfWinExist, %title%
		WinActivate
		sleep 1
		Send {Right}
		sleep 1
	IfWinExist, %CurrentWin%
		WinActivate
	
}