首页 » 操作系统 » Windows » 正文

同步剪贴板内容 AutoHotKey v1

发布者:站点默认
2012/03/1 浏览数(1,233) 分类:Windows 同步剪贴板内容 AutoHotKey v1已关闭评论

sync.ahk

按下 Shift+F9 时将选中内容复制后同步到服务端。Shift+F8 时将服务端的内容粘贴到光标位置。

macOS 版使用 Hammerspoon 实现。注意,加密方法 crypt() 在这里

#NoEnv
#SingleInstance force
codepage = 65001
password := "your_password_here"
url := "https://upall.cn/pasteboard/"
; 远程剪贴板
+f9::
	clipboard := ""
	Send ^c
	ClipWait
	data := clipboard
	encrypted := crypt(data, password, true) ; 加密
	data := encrypted ? encrypted : data
	whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	whr.Open("POST", url, true)
	whr.SetRequestHeader("Content-Type", "text/plain")
	whr.Send(data)
	whr.WaitForResponse()
	resText := whr.ResponseText
	MsgBox, 2000, , %resText% ; 2秒后关闭
	return
	
+f8::
	whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	whr.Open("GET", url, true)
	whr.Send()
	whr.WaitForResponse()
	data := whr.ResponseText
	decrypted := crypt(data, password, false) ; 解密
	data := decrypted ? decrypted : data
	clipboard := data
	Send ^v
	return

server

error_reporting(0);
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST') {
  $data = file_get_contents("php://input");
  $data or exit();
  #file_put_contents('./plain.txt', "\n\n>>>>" . date('Y-m-d H:i:s') . "\n", FILE_APPEND);
  #$r = file_put_contents('./plain.txt', $data, FILE_APPEND);
  $r = file_put_contents('./plain.txt', $data);
  echo $r; 
} else if ($method == 'GET') {
  header('content-type: text/plain; charset=utf-8');
  echo file_get_contents('./plain.txt');
} else {
  exit("unknown mehtod: $method");
}                                                                                                                       

OpenSSL 的示例、PHP 的示例

注:移除加解密功能可以显著减小响应时间。如果你没有服务器,可以试试这个文本存储服务:textdb.dev

点击返回顶部
  1. 留言
  2. 联系方式