|
|||
|
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 |
|
|||
|
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;
}
}
|
|
|||
|
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.
|
![]() |
Was this information helpful? Yes No
| Thread Tools | |
| Display Modes | |
|
|