Willkommen ~Gast!
Registrieren || Einloggen || Hilfe/FAQ || Staff
Probleme mit der Registrierung im Forum? Melde dich unter registerEin Bild.
Autor Beitrag
000
26.05.2002, 19:05
[RMen]OneStone



Hi, ich hab' mal für Megge ein kleines Proggy gemacht, mit dem man die Maus mit dem Joystick steuern kann, nur klicken funktioniert noch nicht. Einfach die ge-.rar-te Datei ausführen und lossteuern =)

Joystick 2 Mouse (Verknüpfung speichern unter)

Hier der Source, wer Bugs / Fehler entdeckt bitte posten:
Quellcode:#include <windows.h>
#include <stdio.h>

#pragma comment(lib, "winmm.lib") //hab' ich hier drin, damit jeder den Source kompilieren kann

#define MAX_SCROLL_RATE 10

long CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* szCommandLine, int nShowMode)
{
    {
        WNDCLASS wcWindowClass;

        wcWindowClass.cbClsExtra = 0;
        wcWindowClass.cbWndExtra = 0;

        wcWindowClass.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
        wcWindowClass.hCursor = LoadCursor(0, IDC_ARROW);
        wcWindowClass.hIcon = LoadIcon(0, IDI_ASTERISK);

        wcWindowClass.hInstance = hInstance;
        wcWindowClass.lpfnWndProc = WndProc;

        wcWindowClass.lpszMenuName = 0;
        wcWindowClass.lpszClassName = "1337-PR0GGµ_j2m";

        wcWindowClass.style = CS_VREDRAW | CS_HREDRAW;

        if(!RegisterClass(&wcWindowClass))
            return 0xFE;
    }

    if(!CreateWindowEx(0, "1337-PR0GGµ_j2m", 0, WS_POPUP, 0, 0, 0, 0, 0, 0, hInstance, 0))
        return 0xFE;

    {
        MSG msgMessage;

        while(GetMessage(&msgMessage, 0, 0, 0))
        {

            TranslateMessage(&msgMessage);
            DispatchMessage(&msgMessage);
        }
    }

    return 0;
}

long CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
    switch(nMsg)
    {
    case WM_CREATE:
        {
            joyReleaseCapture(0);
            joySetCapture(hWnd, 0, 1, false);            
        }
        return 0;

    case MM_JOY1BUTTONDOWN:
        //Click simulating here
        return 0;

    case MM_JOY1MOVE:
        {
            int x = LOWORD(lParam), y = HIWORD(lParam);
            POINT pPos;
            GetCursorPos(&pPos);

            if(LOWORD(lParam) < 24000)
                pPos.x -= (long)(((float) (24000 - LOWORD(lParam)) / 24000.0f) * MAX_SCROLL_RATE);
            else if(LOWORD(lParam) > 40000)
                pPos.x += (long)(((float)(LOWORD(lParam) - 40000) / 24000.0f) * MAX_SCROLL_RATE);

            if(HIWORD(lParam) < 24000)
                pPos.y -= (long)(((float)(24000 - HIWORD(lParam)) / 24000.0f) * MAX_SCROLL_RATE);
            else if(HIWORD(lParam) > 40000)
                pPos.y += (long)(((float)(HIWORD(lParam) - 40000) / 24000.0f) * MAX_SCROLL_RATE);

            SetCursorPos(pPos.x, pPos.y);
        }

        return 0;

    case WM_CLOSE:        
        joyReleaseCapture(0);
        DestroyWindow(hWnd);
        PostQuitMessage(0);
        return 0;

    default:
        return DefWindowProc(hWnd, nMsg, wParam, lParam);
    }
}

Das einzige, was ich noch suche, ist, wie man einen Mausklick simuliert.

--

georg-wicherski@pixel-house.net | http://www.pixel-house.net/ - Coding Resource| http://www.google.de/


Dieser Beitrag wurde am 26.05.2002 um 19:06 von [RMen]OneStone bearbeitet.
zum Seitenanfang zum Seitenende Profil || Suche
001
26.05.2002, 19:21
Retro



das mit der maus geht doch einfach =)Quellcode:mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); // taste runter

mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // tase rauf
den rest kannste dir denken ... =)

so, und jetzt cya, muss auf abschlussfahrt :D

--

shielding people from their own stupidity is an evolutionary step backwards anyway.

/* God is dead!............Nietzsche */
/* Nietzsche is dead!......God */
/* Nietzsche is God!.......The Dead */


Dieser Beitrag wurde am 26.05.2002 um 19:21 von Retro bearbeitet.
zum Seitenanfang zum Seitenende Profil || Suche
002
26.05.2002, 19:51
[RMen]OneStone



Danke, geupdter Code sieht jetzt so aus:
Quellcode:case MM_JOY1BUTTONDOWN:
        {
            POINT pPos;
            GetCursorPos(&pPos);
            
            if(wParam & JOY_BUTTON1CHG)
                mouse_event(MOUSEEVENTF_LEFTDOWN, pPos.x, pPos.y, 0, 0);

            if(wParam & JOY_BUTTON2CHG)
                mouse_event(MOUSEEVENTF_RIGHTDOWN, pPos.x, pPos.y, 0, 0);
        }
        return 0;

    case MM_JOY1BUTTONUP:
        {
            POINT pPos;
            GetCursorPos(&pPos);
        
            if(wParam & JOY_BUTTON1CHG)
                mouse_event(MOUSEEVENTF_LEFTUP, pPos.x, pPos.y, 0, 0);

            if(wParam & JOY_BUTTON2CHG)
                mouse_event(MOUSEEVENTF_RIGHTUP, pPos.x, pPos.y, 0, 0);
        }

CYA, Georg

--

georg-wicherski@pixel-house.net | http://www.pixel-house.net/ - Coding Resource| http://www.google.de/

zum Seitenanfang zum Seitenende Profil || Suche
003
27.05.2002, 14:43
(someone)



wie kann ich den cooliehat zum scrollen benutzen ? :D

--

zum Seitenanfang zum Seitenende Profil || Suche
004
27.05.2002, 16:22
[RMen]OneStone



Sorry, ich weiss leider nicht was ein Cooliehat ist. Ein Kühl-Hut? =)

--

georg-wicherski@pixel-house.net | http://www.pixel-house.net/ - Coding Resource| http://www.google.de/

zum Seitenanfang zum Seitenende Profil || Suche
005
27.05.2002, 17:23
Megge



ich würds so machen:

jeder dieser 8 richtungen bei diesem mini-joystick aufm joystick hat ja nen namen:
bei dem nach unten einfach onpressdown den pagedown button simulieren..

ich weiss natürlich nicht, was für events es alles gibt, aber sowas sollte relativ leicht sein

--

zum Seitenanfang zum Seitenende Profil || Suche
006
27.05.2002, 19:55
(someone)



du weißt nicht zufällig die namen?

irgendeine verwendung muss es doch auch für die z-achse geben...

--

zum Seitenanfang zum Seitenende Profil || Suche
007
27.05.2002, 23:19
Joker



lol, das ist ja voll der Spass =)

ich hab mal nach einer liste gesucht mit den befehlen wie mouse_event(MOUSEEVENTF_LEFTDOWN, pPos.x, pPos.y, 0, 0); aber leider nichts brauchbares gefunden (tastaturbefehle) ... ich hab wohl mit den falschen wörter gesucht... kann mir jemand ein tip geben? (nein ich hab kein buch)

--

-=[ Aigu.ch ]=-

zum Seitenanfang zum Seitenende Profil || Suche
008
27.05.2002, 23:33
Leviathan



also zu der funktion mouse_event steht etwas in der dokumentation zu msvc++, da steht auch eine kleine liste mit möglichen arten der aktionen (z.b. MOUSEEVENTF_LEFTDOWN)

--

Entities: HL | HL²
Kompilierfehler
r_speeds | mehr über r_speeds

zum Seitenanfang zum Seitenende Profil || Suche
009
28.05.2002, 14:55
[RMen]OneStone



mouse_event
The mouse_event function synthesizes mouse motion and button clicks.

Windows NT: This function has been superseded. Use SendInput instead.

VOID mouse_event(
DWORD dwFlags, // flags specifying various motion/click variants
DWORD dx, // horizontal mouse position or position change
DWORD dy, // vertical mouse position or position change
DWORD dwData, // amount of wheel movement
DWORD dwExtraInfo
// 32 bits of application-defined information
);

Parameters
dwFlags
A set of flag bits that specify various aspects of mouse motion and button clicking. The bits in this parameter can be any reasonable combination of the following values: Value Meaning
MOUSEEVENTF_ABSOLUTE Specifies that the dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.
MOUSEEVENTF_MOVE Specifies that movement occurred.
MOUSEEVENTF_LEFTDOWN Specifies that the left button is down.
MOUSEEVENTF_LEFTUP Specifies that the left button is up.
MOUSEEVENTF_RIGHTDOWN Specifies that the right button is down.
MOUSEEVENTF_RIGHTUP Specifies that the right button is up.
MOUSEEVENTF_MIDDLEDOWN Specifies that the middle button is down.
MOUSEEVENTF_MIDDLEUP Specifies that the middle button is up.
MOUSEEVENTF_WHEEL Windows NT: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is given in dwData

dx
Specifies the mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual x-coordinate; relative data is given as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved.
dy
Specifies the mouse's absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual y-coordinate; relative data is given as the number of mickeys moved.
dwData
If dwFlags is MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
If dwFlags is not MOUSEEVENTF_WHEEL, then dwData should be zero.

dwExtraInfo
Specifies an additional 32-bit value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.
Return Values
This function has no return value.

Remarks
If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy hold information about that motion. The information is given as absolute or relative integer values.

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.

If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify relative motions from when the last mouse event was generated (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up).

Relative mouse motion is subject to the settings for mouse speed and acceleration level. An end user sets these values using the Mouse control panel application. An application obtains and sets these values with theSystemParametersInfo function.

The system applies two tests to the specified relative mouse motion when applying acceleration. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse acceleration level is not zero, the operating system doubles the distance. If the specified distance along either the x or y axis is greater than the second mouse threshold value, and the mouse acceleration level is equal to two, the operating system doubles the distance that resulted from applying the first threshold test. It is thus possible for the operating system to multiply relatively-specified mouse motion along the x or y axis by up to four times.

Once acceleration has been applied, the system scales the resultant value by the desired mouse speed. Mouse speed can range from 1 (slowest) to 20 (fastest) and represents how much the pointer moves based on the distance the mouse moves. The default value is 10, which results in no additional modification to the mouse motion.

The mouse_event function is used to synthesize mouse events by applications that need to do so. It is also used by applications that need to obtain more information from the mouse than its position and button state. For example, if a tablet manufacturer wants to pass pen-based information to its own applications, it can write a dynamic-link library (DLL) that communicates directly to the tablet hardware, obtains the extra information, and saves it in a queue. The DLL then calls mouse_event with the standard button and x/y position data, along with, in the dwExtraInfo parameter, some pointer or index to the queued extra information. When the application needs the extra information, it calls the DLL with the pointer or index stored in dwExtraInfo, and the DLL returns the extra information.

Windows CE: Windows CE does not support the MOUSEEVENTF_WHEEL constant in the dwFlags parameter.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winuser.h.
Import Library: Use user32.lib

--

georg-wicherski@pixel-house.net | http://www.pixel-house.net/ - Coding Resource| http://www.google.de/

zum Seitenanfang zum Seitenende Profil || Suche
010
28.05.2002, 14:57
[RMen]OneStone



Ich kann es leider nicht ausprobieren (kein Z-Joystick), aber es gibt eine MM_JOY1ZMOVE, welche auf Bewegungen "in die Tiefe" reagiert, der obige Code ließe sich also einfach mit einem case MM_JOY1ZMOVE: erweitern. LOWORD(lParam) enthälz dann die Z-Position.

--

georg-wicherski@pixel-house.net | http://www.pixel-house.net/ - Coding Resource| http://www.google.de/

zum Seitenanfang zum Seitenende Profil || Suche
011
28.05.2002, 20:00
thinktank



OneStone, glaubst du etwa wirklich, dass MS so blöd ist ? ( bezogen auf die Autorenversion - Warnung )
ICh meine MS wird wohl kaum diesen Thread finden, aber dachtest du, dass die Warnung nur auf deinem Comp kommt =) ?

OK genug des Gelästers =) :

Ich verstehe diese Zeilen nicht :

Zitat:

if(LOWORD(lParam) < 24000)
pPos.x -= (long)(((float) (24000 - LOWORD(lParam)) / 24000.0f)*MAX_SCROLL_RATE);
else if(LOWORD(lParam) > 40000)
pPos.x += (long)(((float)(LOWORD(lParam) - 40000) / 24000.0f) * MAX_SCROLL_RATE);
if(HIWORD(lParam) < 24000)
pPos.y -= (long)(((float)(24000 - HIWORD(lParam)) / 24000.0f) * MAX_SCROLL_RATE);
else if(HIWORD(lParam) > 40000)
pPos.y += (long)(((float)(HIWORD(lParam) - 40000) / 24000.0f) * MAX_SCROLL_RATE);
SetCursorPos(pPos.x, pPos.y);

Die if Abfragen fragen sicher ab, ob der Cursor sich nach rechts oder nach links bewegen soll ( bzw. nach unten / oben ). Aber warum dieses mega-Gemurkse dort ?

--


Dieser Beitrag wurde am 29.05.2002 um 00:18 von thinktank bearbeitet.
zum Seitenanfang zum Seitenende Profil || Suche
012
29.05.2002, 15:30
[RMen]OneStone



O.K.
1. Ähm, dass die wo anders auch kommt weiß ich. Ich update dass mal, hab' das aus Versehen mit einer falschen Version kompiliert, ich hab' natürlich 2 und die Standard ist gekauft!
2. Das ist, damit man mit der Stärke der wegschiebung vom Zentrum (Krieg ich jetzt nen Nobelpreis?) schneller "fährt".

--

georg-wicherski@pixel-house.net | http://www.pixel-house.net/ - Coding Resource| http://www.google.de/

zum Seitenanfang zum Seitenende Profil || Suche