//
// keyboardMouse.c modified to send mouse move to explore 
http://www.dougrice.plus.com/dev/DigiSpark/keyboardMouse.c
// keystroke.c - Pauses, then simulates a key press
// and release of the "A" key.
//
// Written by Ted Burke - last updated 17-4-2012
//
// To compile with MinGW:
//
//      gcc -o keystroke.exe keystroke.c
//
// ..\tcc keyboardMouse.c -luser32
//
// To run the program:
//
//      keyboardMouse.exe
//
// ...then switch to e.g. a Notepad window and wait
// 5 seconds for the cursor to be positioned. 
//
 
// Because the SendInput function is only supported in
// Windows 2000 and later, WINVER needs to be set as
// follows so that SendInput gets defined when windows.h
// is included below.
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event


#define WINVER 0x0500
#include <windows.h>
 
 
//#include <shellapi.h>
#include <stdlib.h>

/*
	winuser.h
	
VOID mouse_event(
  [in] DWORD     dwFlags,
  [in] DWORD     dx,
  [in] DWORD     dy,
  [in] DWORD     dwData,
  [in] ULONG_PTR dwExtraInfo
);	

  typedef struct tagINPUT {
    DWORD type;
    union {
      MOUSEINPUT mi;
      KEYBDINPUT ki;
      HARDWAREINPUT hi;
    };
  } INPUT,*PINPUT,*LPINPUT;

 typedef struct tagMOUSEINPUT {
    LONG dx;
    LONG dy;
    DWORD mouseData;
    DWORD dwFlags;
    DWORD time;
    ULONG_PTR dwExtraInfo;
  } MOUSEINPUT,*PMOUSEINPUT,*LPMOUSEINPUT;

  typedef struct tagKEYBDINPUT {
    WORD wVk;
    WORD wScan;
    DWORD dwFlags;
    DWORD time;
    ULONG_PTR dwExtraInfo;
  } KEYBDINPUT,*PKEYBDINPUT,*LPKEYBDINPUT;

*/
 
int main()
{
    // This structure will be used to create the keyboard
    // input event.
    INPUT ip;
    printf( "pause 5 seconds to position carate");
    // Pause for 5 seconds.
    Sleep(5000);
 
    // Set up a generic keyboard event.
    ip.type = INPUT_MOUSE;

	/* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event
	If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.
	*/
	
	ip.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
	ip.mi.dx = ( LONG ) 10000;
	ip.mi.dy = ( LONG ) 10000;
	ip.mi.mouseData= ( LONG ) 0;
	ip.mi.time = 0;
	ip.mi.dwExtraInfo = ( ULONG_PTR ) 0;
	
	SendInput(1, &ip, sizeof(INPUT));
	
    Sleep(1000);
    // Set up a generic keyboard event.
    ip.type = INPUT_MOUSE;
	ip.mi.dwFlags = MOUSEEVENTF_MOVE ;
	ip.mi.dx = ( LONG ) 10;
	ip.mi.dy = ( LONG ) 10;
	ip.mi.mouseData= ( LONG ) 0;
	ip.mi.time = 0;
	//ip.mi.dwData= ( LONG ) 0;
	ip.mi.dwExtraInfo = ( ULONG_PTR ) 0;
 
 
 /*
    // Set up a generic keyboard event.
    ip.type = INPUT_KEYBOARD;
    ip.ki.wScan = 0; // hardware scan code for key
    ip.ki.time = 0;
    ip.ki.dwExtraInfo = 0;
 
    // Press the "A" key
    ip.ki.wVk = 0x41; // virtual-key code for the "a" key
    ip.ki.dwFlags = 0; // 0 for key press
    SendInput(1, &ip, sizeof(INPUT));
 
    // Release the "A" key
    ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
 */
 
	SendInput(1, &ip, sizeof(INPUT));
    Sleep(1000);
	SendInput(1, &ip, sizeof(INPUT));
    Sleep(1000);


    // Exit normally
    return 0;
}
 
