Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Eat repeated keys and mouse clicks

Author
Message
nodapro
16
Years of Service
User Offline
Joined: 14th Mar 2008
Location:
Posted: 23rd Mar 2008 05:36
This has been discussed elsewhere by others. Here I only want to share an alternative method. Hope it is useful in some cases.

[#include "DarkGDK.h"
#include "dinput.h"

int KeyPressed ( void )
{
int iScanCode = dbScanCode ( );
if ( iScanCode )
{
while ( dbScanCode ( ) == iScanCode );
return iScanCode;
}
else
return 0;
}

int MouseClicked ( void )
{
int iButton = dbMouseClick ( );
if ( iButton )
{
while ( dbMouseClick ( ) == iButton );
return iButton;
}
else
return 0;
}

// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );

// our main loop
while ( LoopGDK ( ) )
{
int iScanCode = KeyPressed ( );
if ( iScanCode == DIK_SPACE )
{
dbPrint ( "Space pressed" );
}
if ( iScanCode == DIK_F1 )
{
dbPrint ( "F1 pressed" );
}

int iButton = MouseClicked ( );
if ( iButton == 1 )
{
dbPrint ( "Leftbutton pressed" );
}
if ( iButton == 2 )
{
dbPrint ( "Rightbutton pressed" );
}
dbSync ( );
}

// return back to windows
return;
}]
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 24th Mar 2008 18:28
Could you wrap it in a code tag for us?

[ c o d e ]

code here

[ / c o d e ]

(Without the spaces in the tags of course

nodapro
16
Years of Service
User Offline
Joined: 14th Mar 2008
Location:
Posted: 24th Mar 2008 22:41
Sorry, I was trying to do it, but didn't figure out how ...

Hope this one is correct.

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 24th Mar 2008 22:48
Nothing wrong - you need to use the edit button thats all.. A mod might help ya.

As for your question...

I don't eat keys or mouse anything... but I DO keep a copy of the PREVIOUS key and MOUSE x,y coords so I have them.

For example, I only count a click if the button1=TRUE but button1Old=false.... which eliminates registering the same Mouse down twice.

Now... if you add TIMER into the equation... you can compare how much time has elapsed between key presses if they are the same letter for example.

That approach might help.

Login to post a reply

Server time is: 2024-09-29 15:15:23
Your offset time is: 2024-09-29 15:15:23