Mouse Events

Ben Lewis
2012-07-21
2012-07-23
  • Ben Lewis - 2012-07-21

    I would like to use mouse events in my Twincat project. To do this I have included the TcMouseEvents.lib library in my project.

    This library has the following functions:
    GetLastLeftMouseDownEvent
    GetLastLeftMouseUpEvent
    GetLastMouseMoveEvent
    GetLastRightMouseDownEvent
    GetLastRightMouseUpEvent
    MouseShowCursor
    SetWindowToForeground
    UseSIP

    My target is a WinCE based panel with an ARM processor.

    If I try to use any of the functions that contain a POINTER TO MOUSEEVENT then my project does not run. It will compile and download but when the applications tries to start I get the following error:

    Communication Error (# 0): Performed Logout"

    Examples of functions that use a POINTER TO MOUSEEVENT include:

    GetLastLeftMouseDownEvent
    GetLastLeftMouseUpEvent
    GetLastMouseMoveEvent

    On the other hand if I use the MouseShowCursor function (which does not include a POINTER TO MOUSEEVENT) my project will run as expected.

    From this it seems that the library is linking ok but I'm having trouble with functions that use a "POINTER TO MOUSEEVENT"

    A very simple project looks like this:

    PROGRAM MAIN
    VAR
    pLeftMouseDownEvent: POINTER TO MOUSEEVENT;
    pRightMouseDownEvent: POINTER TO MOUSEEVENT;
    pMouseMoveEvent: POINTER TO MOUSEEVENT;
    bGetLastLeftMouseDownEvent: BOOL;
    bGetLastRightMouseDownEvent: BOOL;
    bGetLastMouseMoveEvent: BOOL;
    END_VAR
    bGetLastLeftMouseDownEvent:=GetLastLeftMouseDownEv ent(pLeftMouseDownEvent);
    bGetLastRightMouseDownEvent:=GetLastRightMouseDown Event(pRightMouseDownEvent);
    bGetLastMouseMoveEvent:=GetLastMouseMoveEvent(pMou seMoveEvent);
    MouseShowCursor(FALSE);
    

    I've included the following libs:
    TcMouseEvents.lib
    STANDARD.LIB
    SysLibVisu.lib
    SysLibTargetVisu.lib

    Has anybody been able to get mouse events to work on a CE target?

    The CoDeSys manual says the following but I'm not sure how to implement it:

    Zitat:
    The mouse handling also has to meet certain special requirements. As the visualisation code can not be executed often, mouse actions have to be saved so that later on, during the next run through the corresponding code area, they can be processed. For this purpose an array should be occupied which is able to save an even number of mouse-click actions. The same applies for all mouse movements after the activation of a tap (toggle FALSE) button, they too have to be saved.

    Any help with this would be much appreaciated.

    Regards, Ben

     
  • Ben Lewis - 2012-07-23

    I've now got this working. Just in case anybody needs to do this in the future here's an example of how to implement mouse events.

    PROGRAM MAIN
    VAR
    leftMouseDownEvent: MOUSEEVENT;
    rightMouseDownEvent: MOUSEEVENT;
    mouseMoveEvent: MOUSEEVENT;
    END_VAR
    GetLastLeftMouseDownEvent(ADR(leftMouseDownEvent));
    GetLastRightMouseDownEvent(ADR(rightMouseDownEvent));
    GetLastMouseMoveEvent(ADR(mouseMoveEvent));
    MouseShowCursor(FALSE);
    
     
  • shooter - 2012-07-23

    The mouse will be very slow, and not all events will be seen by the program, however this is one of the better solutions.

     

Log in to post a comment.