Created
November 6, 2016 17:57
-
-
Save sandinist/3a39457601436d7e1f2c5700ea42f04f to your computer and use it in GitHub Desktop.
Screen fullpath to PasteBoard in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.IO; | |
using System.Collections; | |
public class CallTest : MonoBehaviour | |
{ | |
private GameObject theta; | |
void Update() | |
{ | |
if (Input.GetKeyDown(KeyCode.C)) | |
{ | |
WinApi.ClipItemPath(480, 150); | |
Invoke("DelayMethod", 0.5f); | |
} | |
if (Input.GetKeyDown(KeyCode.V)) | |
{ | |
WinApi.ClipItemPath(330, 280); | |
Invoke("DelayMethod", 0.5f); | |
} | |
} | |
void DelayMethod() | |
{ | |
Debug.Log(GUIUtility.systemCopyBuffer); // 前後に " が付いているので除去して使ってください。 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System; | |
using System.Text; | |
using System.Runtime.InteropServices; | |
public class WinApi : MonoBehaviour | |
{ | |
[DllImport("USER32.dll")] | |
static extern void SetCursorPos(int X, int Y); | |
[DllImport("USER32.dll")] | |
static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); | |
[DllImport("user32.dll")] | |
public static extern uint keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); | |
private const int MOUSEEVENTF_LEFTDOWN = 0x0002; | |
private const int MOUSEEVENTF_LEFTUP = 0x0004; | |
private const int MOUSEEVENTF_RIGHTDOWN = 0x0008; | |
private const int MOUSEEVENTF_RIGHTUP = 0x0010; | |
private const int KEYEVENTF_EXTENDEDKEY = 0x0001; | |
private const int KEYEVENTF_KEYUP = 0x0002; | |
private const int VK_LSHIFT = 0xA0; | |
private const int VK_RSHIFT = 0xA1; | |
private const int VK_A = 0x41; | |
public static void ClipItemPath(int x, int y) | |
{ | |
// 指定座標にカーソルを移動してクリック | |
SetCursorPos(x, y); | |
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); | |
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); | |
// Shift + 右クリック + A でパスをクリップボードへコピー | |
keybd_event(VK_LSHIFT, 0x45, KEYEVENTF_EXTENDEDKEY, 0); | |
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0); | |
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); | |
keybd_event(VK_LSHIFT, 0x45, KEYEVENTF_KEYUP, 0); | |
keybd_event(VK_A, 0x45, KEYEVENTF_EXTENDEDKEY, 0); | |
keybd_event(VK_A, 0x45, KEYEVENTF_KEYUP, 0); | |
// Shiftキーが押しっぱなしになる場合があるので対策 | |
keybd_event(VK_RSHIFT, 0x45, KEYEVENTF_EXTENDEDKEY, 0); | |
keybd_event(VK_RSHIFT, 0x45, KEYEVENTF_KEYUP, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment