This file contains hidden or 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
// マウス操作のイベントが発生したら実行されるメソッド | |
private static IntPtr MouseInputCallback (int nCode, IntPtr wParam, IntPtr lParam) { | |
if (nCode < 0) { | |
// マウスのイベントに紐付けられた次のメソッドを実行する。メソッドがなければ処理終了。 | |
return NativeMethods.CallNextHookEx (_mouseHookId, nCode, wParam, lParam); | |
} | |
MSLLHOOKSTRUCT param = Marshal.PtrToStructure<MSLLHOOKSTRUCT> (lParam); | |
Win32Point mousePosition = new Win32Point { |
This file contains hidden or 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 System; | |
using System.Runtime.InteropServices; | |
namespace KusaMochiAutoLibrary.NativeFunctions | |
{ | |
[StructLayout(LayoutKind.Sequential)] | |
public struct Win32Point | |
{ | |
public Int32 X; | |
public Int32 Y; |
This file contains hidden or 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
// アプリのメインウィドウ | |
System.Windows.Window MainWindow = System.Windows.Application.Current.MainWindow; | |
// DIPを物理的なピクセルに変換するための係数をもとめる。 | |
PresentationSource MainWindowPresentationSource = PresentationSource.FromVisual(MainWindow); | |
Matrix m = MainWindowPresentationSource.CompositionTarget.TransformToDevice; | |
double dpiWidthFactor = m.M11; | |
double dpiHeightFactor = m.M22; | |
// DIPのスクリーンサイズに係数を掛け算して、スクリーンの解像度をもとめる。 |
This file contains hidden or 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
// これでは正確に取得できない場合がある。 | |
double ScreenHeight = SystemParameters.PrimaryScreenHeight; | |
double ScreenWidth = SystemParameters.PrimaryScreenWidth; |
This file contains hidden or 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
Keys winFormsKey = Keys.A; | |
short key = (short)winFormsKey; | |
// 以下同様 |
This file contains hidden or 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
// キーコード | |
short key = 65; | |
INPUT[] inputs = new INPUT[] { | |
new INPUT { | |
type = NativeMethods.INPUT_KEYBOARD, | |
ui = new INPUT_UNION { | |
keyboard = new KEYBDINPUT { | |
wVk = key, | |
wScan = (short) NativeMethods.MapVirtualKey (key, 0), |
This file contains hidden or 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 System; | |
namespace MyNamespace { | |
///// APIの利用に必要な構造体・共用体の定義 ここから ///// | |
[StructLayout(LayoutKind.Sequential)] | |
public struct Win32Point | |
{ | |
public Int32 X; | |
public Int32 Y; | |
}; |
This file contains hidden or 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
// マウスホイールの回転量(マイナスで下回転、プラスで上回転) | |
int amount = -3; // 下に3段階回転させる。 | |
// マウスポインタの左右位置(左端が0) | |
int x = 100; | |
// マウスポインタの上下位置(上端が0) | |
int y = 200; | |
INPUT input = new INPUT |
This file contains hidden or 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
Win32Point mousePosition = new Win32Point { | |
X = 0, | |
Y = 0 | |
}; | |
// マウスポインタの現在位置を取得する。 | |
NativeMethods.GetCursorPos (ref mousePosition); | |
// マウスポインタの現在位置でマウスの左ボタンの押し下げ・押し上げを連続で行うためのパラメータを設定する。 | |
INPUT[] inputs = new INPUT[] { |
This file contains hidden or 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 System; | |
namespace MyNamespace { | |
///// APIの利用に必要な構造体・共用体の定義 ここから ///// | |
[StructLayout(LayoutKind.Sequential)] | |
public struct Win32Point | |
{ | |
public Int32 X; | |
public Int32 Y; | |
}; |