Hi there
I'd like to make an app which require to use of the mouse
So I had two choices:
1. Install Ashikase's mousesupport and use it
When I want to simulate a mouse click, I send to mousesupport the event (0, 0, buttons,
NO) to tell it to move to 0, 0 as relative coordinates (ie don't move)
Unfortunately (or because I didn't really understand how to use it) when I do this, mousesupport doesn't use the current position of the mouse to move to (0, 0 as relative) but it uses (0, 0 as absolute) ie the cursor goes to top left of the screen before clicking
So I wanted to fork mousesupport
2. But to build a tweak I apparently need Theos which use perl
Once again it failed because gcc breaks perl ("Bus error 10")
So what I'm looking for is a solution to one of these problems
I'm working on that for few days now, if someone can help me it would be really appreciated
If something wasn't clear, please tell me I will try to reformulate
Here is my code (1.) :
#include <CoreFoundation/CoreFoundation.h>
#include <stdio.h>
#include <substrate.h>
#include <mach/mach.h>
static CFMessagePortRef ashikase_;
static CFDataRef cfTrue_;
static CFDataRef cfFalse_;
static BTN_RIEN = 0;
static BTN_TOUCH = 1;
static BTN_LOCK = 2;
static BTN_HOME = 4;
typedef struct {
float x, y;
int buttons;
BOOL absolute;
} MouseEvent;
MouseEvent event_;
static CFDataRef cfEvent_;
typedef enum {
MouseMessageTypeEvent,
MouseMessageTypeSetEnabled
} MouseMessageType;
void writelog(char * txt){
FILE* fp;
fp = fopen("fichier.txt", "a" );
fprintf(fp, txt);
fprintf(fp, "\n");
fclose(fp);
}
void clearlog(){
FILE* fp;
fp = fopen("fichier.txt", "w" );
fprintf(fp, "");
fclose(fp);
}
static bool Ashikase() {
if (ashikase_ == NULL)
ashikase_ = CFMessagePortCreateRemote(kCFAllocatorDefault, CFSTR("jp.ashikase.mousesupport"));
if (ashikase_ != NULL)
return true;
return false;
}
static void AshikaseSendEvent(float x, float y, int buttons, bool abs) {
event_.x = x;
event_.y = y;
event_.buttons = buttons;
event_.absolute = abs?YES:NO;
printf("\ne_ = %f, %f, %s\n", x, y, event_.absolute?"true":"false");
printf("arg = %f, %f, %s\n", x, y, abs?"true":"false");
CFMessagePortSendRequest(ashikase_, MouseMessageTypeEvent, cfEvent_, 0, 0, NULL, NULL);
}
static bool AshikaseSetEnabled(int enabled) {
if (!Ashikase())
return false;
CFMessagePortSendRequest(ashikase_, MouseMessageTypeSetEnabled, enabled ? cfTrue_ : cfFalse_, 0, 0, NULL, NULL);
return true;
}
void MouseGoto(float x, float y){
AshikaseSendEvent(x, y, 0, true);
}
void MouseClick(int btn){
AshikaseSendEvent(0, 0, btn, false);
AshikaseSendEvent(0, 0, 0, false);
}
int main(int argc, char ** argv)
{
if(argc<4){
printf("Usage : %s cursor[0,1] command\nCommands :\n move x y\n click button[nothing, touch, lock, home = 0, 1, 2, 4]\n", argv[0]);
return 0;
}
bool value;value = true;cfTrue_ = CFDataCreate(kCFAllocatorDefault, &value, sizeof(value));
value = false;cfFalse_ = CFDataCreate(kCFAllocatorDefault, &value, sizeof(value));
cfEvent_ = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, &event_, sizeof(event_), kCFAllocatorNull);
int cursor;
sscanf(argv[1],"%i",&cursor);
if(!AshikaseSetEnabled(cursor)){
printf("jp.ashikase.mousesupport must be installed.\nExiting.");
return 0;
}
if(strcmp(argv[2], "move") == 0){
if(argc<5){printf("Not enough arguments for command 'move'.\nExiting.");}
float x, y;
sscanf(argv[3],"%f",&x);
sscanf(argv[4],"%f",&y);
MouseGoto(x, y);
}else if(strcmp(argv[2], "click") == 0){
int btn;
sscanf(argv[3],"%i",&btn);
MouseClick(btn);
}
CFMessagePortInvalidate(ashikase_);
CFRelease(ashikase_);
return 0;
}EDIT : I just saw
"Getting Started With Theos" I'll look into it, but if I can avoid making a new tweak it would be better