将文本复制到剪贴板的最佳方法是什么?(多浏览器)
我试过了:
function copyToClipboard(text) {
if (window.clipboardData) { // Internet Explorer
window.clipboardData.setData("Text", text);
} else {
unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
clipboardHelper.copyString(text);
}
}
Run Code Online (Sandbox Code Playgroud)
但在Internet Explorer中,它会出现语法错误.在Firefox中,它说unsafeWindow is not defined.
没有闪存的好技巧:Trello如何访问用户的剪贴板?
我需要知道如何来模拟按键键盘输入W,S,A,D.
我用过SendKeys没有用的InputSimulator图书馆没有修复.
我正在尝试做的是让游戏(战场,自然选择等新的FPS游戏)等应用程序将这些模拟键注册为真正的击键.我正在尝试创建一个虚拟控制器程序,其中外部控件将注册为这些游戏的键盘输入.
有没有办法手动模拟键盘输入,就像有这样的东西?
[DllImport("user32.dll",
CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags,
uint dx,
uint dy,
int cButtons,
uint dwExtraInfo);
Run Code Online (Sandbox Code Playgroud) 所以我遇到了一个问题,我正在尝试将密钥发送到游戏中,并且我将游戏放在前台,SetForegroundWindow并且我正在使用SendInputsAPI将密钥发送到游戏中.
如果我专注于另一个应用程序,密钥将被发送到该应用程序,但只要我专注于我想要发送密钥的应用程序,它们就不会出现在那里.
我想节省一些时间为我的公会招募公会成员,并且我正试图将钥匙发送给游戏.
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr GetMessageExtraInfo();
[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
Process[] procs = Process.GetProcessesByName("BlackDesert64");
if (procs.Length > 0)
{
if (procs[0].MainWindowHandle != IntPtr.Zero)
{
SetForegroundWindow(procs[0].MainWindowHandle);
Thread.Sleep(1000);
}
}
INPUT[] inputs = new INPUT[]
{
new INPUT
{
type = INPUT_KEYBOARD,
u = new InputUnion
{
ki = new KEYBDINPUT
{
wVk = 0x49,
wScan = 0049,
dwFlags = …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来模拟Ctrl在C#中按下正确的键,它必须是正确的.我知道这可以为左边的一个做,但我找不到合适的东西.这是我可以模拟手动触发的bsod按键.
谢谢
c# ×3
sendkeys ×2
.net ×1
bsod ×1
clipboard ×1
copy-paste ×1
input ×1
javascript ×1
keyboard ×1
simulation ×1