Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > SWFKit > SWFKit Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2009, 06:23 AM
Senior Member
 
Join Date: Feb 2003
Posts: 212
Default Mouse and swfkit

On the net, I've found a way to use a wii-mote in flash (wiiflash).
No I'ld like to control the mousecursor, so i could use the arrow buttons to change the mouse position.
But flash doesn't have this feature?

How can i change the mouse position and simulate the mousedown mouseclick events?
Is it possible with ffish?
Do I need an extra dll?

I googled a bit and found a mouse dll
here: G-Flash

Maybe it's even possible with the user32.dll
Using Cursors

But i don't now how to implement it in SWFKit.

A nice extra would be if i could use this to control other applications while the swfkit project is running.

Any help is appreciated
Reply With Quote
  #2 (permalink)  
Old 12-13-2009, 08:52 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default

The following code should work, which simulates the mouse motions with keyboard. The left, right, bottom and up keys control the cursor movement, and the 'A', 'S', 'D' keys simulate left button click, right button click, left button double click, respectively.

Code:
struct {
	unsigned int type;
	long dx;
	long dy;
	unsigned int mouseData;
	unsigned int dwFlags;
	unsigned int time;
	pointer dwExtraInfo;
} MOUSEINPUT;

dllimport "user32.dll" stdcall unsigned int SendInput(unsigned int, MOUSEINPUT*, int);
dllimport "kernel32.dll" stdcall void Sleep(unsigned int);


//constants
var INPUT_MOUSE = 0;
var MOUSEEVENTF_MOVE = 1;
var MOUSEEVENTF_LEFTDOWN = 2;
var MOUSEEVENTF_LEFTUP = 4;
var MOUSEEVENTF_RIGHTDOWN = 8;
var MOUSEEVENTF_RIGHTUP = 16;
var MOUSEEVENTF_WHEEL = 256;

// move the mouse cursor
// x, y specify the account of motion
function moveCursor(x, y) {
	mi = new Struct(MOUSEINPUT);
	mi.type = INPUT_MOUSE;
	mi.dx = x;
	mi.dy = y;
	mi.dwFlags = MOUSEEVENTF_MOVE;
	SendInput(1, mi, mi.structSize);
}

// simulate left button down
function leftBtnDown() {
	mi = new Struct(MOUSEINPUT);
	mi.type = INPUT_MOUSE;
	mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
	SendInput(1, mi, mi.structSize);
}

// simulate left button up 
function leftBtnUp() {
	mi = new Struct(MOUSEINPUT);
	mi.type = INPUT_MOUSE;
	mi.dwFlags = MOUSEEVENTF_LEFTUP;
	SendInput(1, mi, mi.structSize);
}

// simulate right button down
function rightBtnDown() {
	mi = new Struct(MOUSEINPUT);
	mi.type = INPUT_MOUSE;
	mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
	SendInput(1, mi, mi.structSize);
}

// simulate right button up
function rightBtnUp() {
	mi = new Struct(MOUSEINPUT);
	mi.type = INPUT_MOUSE;
	mi.dwFlags = MOUSEEVENTF_RIGHTUP;
	SendInput(1, mi, mi.structSize);
}

// simulate left button double click
function leftBtnDblClick() {
	leftBtnDown();
	Sleep(80);
	leftBtnDown();
}

// simulate mouse wheel
function mouseWheel(amount) {
	mi = new Struct(MOUSEINPUT);
	mi.type = INPUT_MOUSE;
	mi.mouseData = amount;
	mi.dwFlags = MOUSEEVENTF_WHEEL;
	SendInput(1, mi, mi.structSize);
}


// simulate mouse events using keyboard events
FlashPlayer.window.onMessage = function (msg, wparam, lparam) {
	//trace(msg);
	switch (msg) {
	case /*WM_KEYDOWN*/0x0100:
		trace(wparam);
		if (wparam == /*VK_LEFT*/0x25) {
			moveCursor(-5, 0);
		} else if (wparam == /*VK_UP*/0x26) {
			moveCursor(0, -5);
		} else if (wparam == /*VK_RIGHT*/0x27) {
			moveCursor(5, 0);
		} else if (wparam == /*VK_BOTTOM*/0x28) {
			moveCursor(0, 5);
		} else if (wparam == /*A*/0x41) {
			leftBtnDown();
		} else if (wparam == /*S*/0x53) {
			rightBtnDown();
		} else if (wparam == /*D*/0x44) {
			leftBtnDblClick();
		}
		break;
	case /*WM_KEYUP*/0x0101:
		if (wparam == /*A*/0x41) {
			leftBtnUp();
		} else if (wparam == /*S*/0x53) {
			rightBtnUp();
		}
		break;
	}
}
Reply With Quote
  #3 (permalink)  
Old 01-02-2010, 09:26 AM
Senior Member
 
Join Date: Dec 2002
Posts: 2,015
Default

If you're using WII remote to control the mouse cousor, the code above should work to control the other windows. The key point is that your program must be able to receive the WII remote messages, and thus call the "SendInput" function to control the mouse cursor, even if it isn't the active window, because when you click another window, that window will be the active window, and your window will loose the focus. Therefore, if you want it to still be able to control the mouse cursor, it must be able to receive the WII remote messages when it isn't the active window.
Reply With Quote
  #4 (permalink)  
Old 01-02-2010, 11:23 AM
Senior Member
 
Join Date: Feb 2003
Posts: 212
Default

Thanks, I'll try it out
Best wishes for 2010
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:03 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.