色々漁ってここまで書いたのですが、sendinputの使用的構文に問題があるのだろうと思います。
自分なりにはここまでしか詰めることができませんでした。
詰めれるような方がいらっしゃいましたら教えてください。
お願いします。
using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using UnityEngine; using System; public class SEIN : MonoBehaviour { [DllImport("user32.dll", SetLastError = true)] private static extern UInt32 SendInput(UInt32 numberOfInputs, ref INPUT inputs, Int32 sizeOfInputStructure); internal struct INPUT { public UInt32 Type; public MOUSEKEYBDHARDWAREINPUT Data; } [StructLayout(LayoutKind.Explicit)] internal struct MOUSEKEYBDHARDWAREINPUT { [FieldOffset(0)] public MOUSEINPUT Mouse; [FieldOffset(0)] public KEYBDINPUT Keyboard; [FieldOffset(0)] public HARDWAREINPUT Hardware; } internal struct KEYBDINPUT { public UInt16 KeyCode; public UInt16 Scan; public UInt32 Flags; public UInt32 Time; public IntPtr ExtraInfo; } internal struct MOUSEINPUT { public Int32 X; public Int32 Y; public UInt32 MouseData; public UInt32 Flags; public UInt32 Time; public IntPtr ExtraInfo; } [DllImport("user32.dll")] public static extern IntPtr GetMessageExtraInfo(); // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { const int num = 2; INPUT[] inp = new INPUT[num]; // (2)キーボード(A)を押す inp[0].Type =0x01; inp[0].Data.Keyboard.KeyCode = 0x30; inp[0].Data.Keyboard.Flags = 0x01 | 0x00; // (3)キーボード(A)を離す inp[1].Type = 0x01; inp[1].Data.Keyboard.KeyCode = 0x30; inp[1].Data.Keyboard.Flags = 0x01 | 0x02; // キーボード操作実行 SendInput(num, ref inp[0], Marshal.SizeOf(inp[0])); } }
なにか問題があるような構文ではないと思うのですが何故なんでしょう・・・?
回答のサンプル文はunityじゃなくてもいいので、どうかコピッったら動作できるようなものをご教授ください!
じゃないとマクロが作れない><><><><
質問2
keybd_eventでは実際の出力でメモ帳にアタッチできなかったのはなぜなのか教えてください。
unityのインプトフィールドには出力されたのですが・・
メモ帳にfocusを当てると作動しませんでした。
やはり納得いかないので再質問させていただきます。
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Runtime.InteropServices; using System.Threading; public class Macro2 : MonoBehaviour { private const int KEYEVENTF_KEYDOWN = 0x0000; private const int KEYEVENTF_KEYUP = 0x0002; [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)] static extern void keybd_event(int bVK, int bScan, int dwflags, int dwExtrainfo); public float men; // Start is called before the first frame update void Start() { Debug.Log("start"); } // Update is called once per frame void Update() { men = Input.GetAxisRaw("LB1"); if (men > 0) { keybd_event(0x61, 0, KEYEVENTF_KEYDOWN, 0); keybd_event(0x61, 0, KEYEVENTF_KEYUP, 0); } } }
ゲムパの入力を取って1を出力するだけなのですが・・・
解説よりはコードをパチッと張ってもらったほうが嬉しいです。
何故なんでしょう・・・?
私は初めて1年もたっていないのですが、できないのは当然でしょうか・・・??????????
回答1件
あなたの回答
tips
プレビュー