Click here to Skip to main content
12,693,891 members (32,584 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++
I am trying to compile my originally visual c++ project on Xcode so I can run it on macOSX and as I can't use windows.h in Xcode/mac I'm looking for alternatives.
Could you give me some ways to replace these subroutines:
UINT SendString(string str)
{
   UINT count = 0;
   for (size_t i = 0; i < str.size();i++)
   {   
      INPUT input[2];
      ::ZeroMemory(input, sizeof(input)); 
      input[0].type = input[1].type = INPUT_KEYBOARD;
      input[0].ki.wVk  = input[1].ki.wVk = VkKeyScan(str[i]);
      input[1].ki.dwFlags = KEYEVENTF_KEYUP;
      count += SendInput(2, input, sizeof(INPUT));
   }
   return count;
}
void SendKey(char key){
	keybd_event(VkKeyScan(key),0,0,0);
	keybd_event(VkKeyScan(key),0,2,0);
}
void MouseMove(int x, int y )
{  
	double fScreenWidth    = ::GetSystemMetrics( SM_CXSCREEN )-1; 
	double fScreenHeight  = ::GetSystemMetrics( SM_CYSCREEN )-1; 
	double fx = x*(65535.0f/fScreenWidth);
	double fy = y*(65535.0f/fScreenHeight);
	INPUT  Input={0};
	Input.type      = INPUT_MOUSE;
	Input.mi.dwFlags  = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
	Input.mi.dx = fx;
	Input.mi.dy = fy;
	::SendInput(1,&Input,sizeof(INPUT));
}
void MouseClick(string button, string mode){
	INPUT    Input={0};
	Input.type = INPUT_MOUSE;
	if(mode == "down"){
		if(button == "left"){Input.mi.dwFlags=MOUSEEVENTF_LEFTDOWN;}else if(button == "right"){Input.mi.dwFlags=MOUSEEVENTF_RIGHTDOWN;}
		::SendInput(1,&Input,sizeof(INPUT));
	}else if(mode == "up"){
		::ZeroMemory(&Input,sizeof(INPUT));
		if(button=="left"){Input.mi.dwFlags=MOUSEEVENTF_LEFTUP;}else if(button=="right"){Input.mi.dwFlags=MOUSEEVENTF_RIGHTUP;}
		::SendInput(1,&Input,sizeof(INPUT));
	}else if(mode == "both"){
		if(button == "left"){Input.mi.dwFlags=MOUSEEVENTF_LEFTDOWN;}else if(button == "right"){Input.mi.dwFlags=MOUSEEVENTF_RIGHTDOWN;}
		::SendInput(1,&Input,sizeof(INPUT));
		::ZeroMemory(&Input,sizeof(INPUT));
		if(button=="left"){Input.mi.dwFlags=MOUSEEVENTF_LEFTUP;}else if(button=="right"){Input.mi.dwFlags=MOUSEEVENTF_RIGHTUP;}
		::SendInput(1,&Input,sizeof(INPUT));
}
}

ShellExecute(NULL, L"open", L"http://google.com", NULL, NULL, SW_SHOWNORMAL);
Posted 12-Dec-12 17:40pm
Dots12386
Updated 13-Dec-12 2:02am
v2
Comments
Sergey Alexandrovich Kryukov 12-Dec-12 22:53pm
   
What's the platform? Tag it. What's the problem? Having declarations from Windows API? You can replace some of them, such as UINT, not those which are Windows-specific...
--SA
Jochen Arndt 13-Dec-12 3:08am
   
You should rephrase your question. I assume you mean something like 'How to convert this Windows code to OS X / iOS using Xcode'.
But there is no simple conversion. You probably must write new code that does the the same tasks using the OS X API. I never wrote programs for OS X / iOS but I'm quite sure that there are no direct replacement functions for SendInput() and ShellExecute().
Pablo Aliskevicius 13-Dec-12 4:50am
   
Maybe not iOS, but Linux?
Jochen Arndt 13-Dec-12 5:02am
   
Using Xcode to develop Linux applications seems to be an advanced task. I assume OS X, eventually iOS. But only the questioner knows.
Jochen Arndt 13-Dec-12 8:39am
   
With the updated question it is now clear what you want. But I already gave you the answer:
You must find OS X API functions that perform the required tasks. For keyboard events (simulating key press events), this might be CGEventCreateKeyboardEvent() and CGEventPost().

The OS X and Windows API are totally different. So you must write completely new code.
MoonDPC 13-Dec-12 9:30am
   
Ok, thanks
Albert Holguin 13-Dec-12 11:20am
   
Maybe post this as solution... otherwise it stays as unanswered.
Jochen Arndt 13-Dec-12 11:59am
   
Done.
Albert Holguin 13-Dec-12 13:04pm
   
Thanks :)

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Text from comments to have an answer.

The OS X and Windows APIs are totally different. So you must write completely new code.

You can try to find OS X API functions that perform the same tasks as the Windows API functions. For keyboard events (simulating key press events), this might be CGEventCreateKeyboardEvent() and CGEventPost().
  Permalink  
Comments
Albert Holguin 13-Dec-12 13:05pm
   
+5, supporting multiple platforms after the fact is always a pain (i.e. not programming for it in advance)
Jochen Arndt 13-Dec-12 13:54pm
   
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100