Page 2 of 3
Posted: Sun Feb 04, 2007 12:16 am
by Matt
The program I'm working on will require the default computer's cursor, otherwise I wouldn't.
Here's the code for the openscreen areas:
Code: Select all
If OpenScreen(tempWidth,tempHeight,DesktopDepth(0),program$)
ShowCursor_(1)
SetClassLong_(ScreenID(),#GCL_HCURSOR,LoadCursor_(0,#IDC_ARROW))
windowSprite = CreateSprite(#PB_Any,tempWidth,tempHeight)
;mouseSprite = LoadSprite(#PB_Any,"cursor.bmp")
;TransparentSpriteColor(mouseSprite,RGB(128,128,128))
..... when the screen closes:
Code: Select all
;ExamineMouse()
;DisplayTransparentSprite(mouseSprite,MouseX(),MouseY())
FlipBuffers()
ExamineKeyboard()
Delay(10)
Until KeyboardPushed(#PB_Key_Grave) And KeyboardPushed(#PB_Key_Escape)
FreeSprite(windowSprite)
;FreeSprite(mouseSprite)
CloseScreen()
ShowCursor_(0)
Another question:
Should Flip Buffers be at the top of my loop, and ClearScreen at the bottom, or FlipBuffers at the bottom and ClearScreen at the top?
Posted: Sun Feb 04, 2007 12:30 am
by Matt
hmm I put a delay(5000) before the windowSprite = CreateSprite(#PB_Any,tempWidth,tempHeight) line, and the mouse showed for 5 seconds.... then I changed the size of the sprite, and the mouse still didn't show, so I don't believe it has to do with the sprite... hmm...
anyideas why?
Posted: Sun Feb 04, 2007 12:36 am
by Fluid Byte
Now I understand. InitMouse() / ExamineMouse() are the problem here. These commands use DirectInput and are superior to the regular input. No chance to get around this but you could still rely on standard mouse input:
Code: Select all
InitSprite() : InitKeyboard()
OpenScreen(640,480,16,"untitled")
ShowCursor_(1)
SetClassLong_(ScreenID(),#GCL_HCURSOR,LoadCursor_(0,#IDC_ARROW))
Repeat
ClearScreen($854422)
ExamineKeyboard()
StartDrawing(ScreenOutput())
If GetAsyncKeyState_(#VK_LBUTTON)
DrawText(10,10,"MOUSE INPUT: LEFT BUTTON")
ElseIf GetAsyncKeyState_(#VK_MBUTTON)
DrawText(10,10,"MOUSE INPUT: MIDDLE BUTTON")
ElseIf GetAsyncKeyState_(#VK_RBUTTON)
DrawText(10,10,"MOUSE INPUT: RIGHT BUTTON")
Else
DrawText(10,10,"MOUSE INPUT: IDLE")
EndIf
GetCursorPos_(cpt.POINT)
DrawText(10,40,"MOUSE POSITION: " + Str(cpt\x) + "," + Str(cpt\y))
StopDrawing()
FlipBuffers()
Until KeyboardPushed(1)
Posted: Sun Feb 04, 2007 12:36 am
by Matt
-edit-
ok I understand.
Thank You!

Posted: Mon Feb 05, 2007 8:40 pm
by Matt
I tried doing that, the mouse shows and everything, but it lags... and my code no longer works trying to figure out if the mouse was pressed or released (check my other mouse post for my code)
Posted: Mon Feb 05, 2007 8:58 pm
by Fluid Byte
Code: Select all
InitSprite()
InitKeyboard()
OpenWindow(0,0,0,800,200,"")
OpenWindowedScreen(WindowID(0),0,0,800,200,0,0,0)
ticks=0
flag=0
pressed=0
ExamineKeyboard()
While Not KeyboardPushed(#PB_Key_Escape)
WindowEvent()
Delay(1)
If GetAsyncKeyState_(#VK_LBUTTON)
ticks+1
flag=1
If ticks >= 200 And pressed = 0
Debug "left pressed"
pressed = 1
EndIf
EndIf
If GetAsyncKeyState_(#VK_LBUTTON)=0
If flag=1
If ticks<200
Debug "left clicked"
Else
Debug "left released"
EndIf
flag=0
ticks=0
pressed = 0
EndIf
EndIf
ExamineKeyboard()
Wend
Posted: Mon Feb 05, 2007 8:58 pm
by Derek
This is the two programs merged together, you won't see the debug output until you quit, then you will see that it was working.
Not sure about the lag that you mentioned, can you explain more, is the cursor juddery or something?
Code: Select all
InitSprite() : InitKeyboard()
OpenScreen(640,480,16,"untitled")
ShowCursor_(1)
SetClassLong_(ScreenID(),#GCL_HCURSOR,LoadCursor_(0,#IDC_ARROW))
ticks=0
flag=0
pressed=0
Repeat
ClearScreen($854422)
ExamineKeyboard()
StartDrawing(ScreenOutput())
If GetAsyncKeyState_(#VK_LBUTTON)
ticks+1
flag=1
If ticks >= 200 And pressed = 0
Debug "left pressed"
pressed = 1
EndIf
EndIf
If Not GetAsyncKeyState_(#VK_LBUTTON)
If flag=1
If ticks<200
Debug "left clicked"
Else
Debug "left released"
EndIf
flag=0
ticks=0
pressed = 0
EndIf
EndIf
GetCursorPos_(cpt.POINT)
DrawText(10,40,"MOUSE POSITION: " + Str(cpt\x) + "," + Str(cpt\y))
StopDrawing()
FlipBuffers()
Until KeyboardPushed(1)
Posted: Mon Feb 05, 2007 9:16 pm
by netmaestro
When you check GetAsyncKeystate_() you should test logical AND with 32768 as that bit is the one that signifies key down or not. There are situations where other bits could be set with the key up, and if you're just checking If GetAsyncKeystate(#key) you can get an incorrect result of the test. This code is recommended:
Code: Select all
If GetAsyncKeyState_(#VK_LBUTTON) & 32768
; key is down
Else
; key is up
EndIf
Posted: Mon Feb 05, 2007 10:51 pm
by Matt
Okay, using GetAsyncKeyState_(#VK_LBUTTON) & 32768 to check when the mouse is down and using Not GetAsyncKeyState_(#VK_LBUTTON) & 32768 to check when it's not down works.
In my program however, as I said, the mouse judders.
Posted: Mon Feb 05, 2007 10:59 pm
by netmaestro
It's not going to fix your judder, it's just the right way to use the GetAsyncKeyState_() if you're testing a key down or up, that's all.
Posted: Mon Feb 05, 2007 11:09 pm
by Matt
Oh I know that,
I was stating that the lag I mentioned earlier is a judder kind of effect.
It doesn't happen when I use the mousebutton function, only the getasynckeystate....
Posted: Tue Feb 06, 2007 12:17 am
by Kaeru Gaman
what do you mean by "judder"?
take a look at my WinScreenMouse example.
http://www.purebasic.fr/english/viewtopic.php?t=25082
I'm using GetAsyncKeystate for the buttons, even tho I use an own mousepointer within the screen.
does the effekt happen there, too?
Posted: Tue Feb 06, 2007 3:42 am
by Matt
No, it does not. Maybe I should post my code?
Posted: Tue Feb 06, 2007 11:16 am
by Derek
Yeah, if you post your code then we can take a look and try and fix it for you, if possible.
Posted: Tue Feb 06, 2007 7:50 pm
by Matt
Code: Select all
If OpenScreen(tempWidth,tempHeight,DesktopDepth(0),program$+" Control Client")
ShowCursor_(1)
SetClassLong_(ScreenID(),#GCL_HCURSOR,LoadCursor_(0,#IDC_ARROW))
windowSprite = CreateSprite(#PB_Any,tempWidth,tempHeight)
;mouseSprite = LoadSprite(#PB_Any,"cursor.bmp")
;TransparentSpriteColor(mouseSprite,RGB(128,128,128))
;Disable Alt-Tab and Alt-ESC
hooklib = OpenLibrary(0,"AltHook.dll")
If hooklib
keyproc=GetFunction(0, "KeyboardProc")
KeyboardHook=SetWindowsHookEx_(#WH_KEYBOARD_LL, keyproc, hooklib, 0)
CallFunction(0, "InitHook", KeyboardHook)
EndIf
leftMouseTicks = 0
leftMouseFlag = 0
leftMousepressed = 0
rightMouseTicks = 0
rightMouseFlag = 0
rightMousePressed = 0
Repeat
ClearScreen(RGB(0,0,0))
;ExamineMouse()
;tempMouseX = MouseX()
;tempMouseY = MouseY()
GetCursorPos_(tempMousePos.POINT)
tempMouseX = tempMousePos\x
tempMouseY = tempMousePos\y
SendNetworkString(tempClient,"MOU|"+Str(tempMouseX)+"|"+Str(tempMouseY))
;ExamineMouse()
If GetAsyncKeyState_(#VK_LBUTTON) & 32768
leftMouseTicks = leftMouseTicks + 1
leftMouseFlag = 1
If leftMouseTicks >= totalTicks And leftMousePressed = 0
Debug "left pressed"
leftMousePressed = 1
SendNetworkString(tempClient,"SIM|STARTDRAG")
EndIf
EndIf
If Not GetAsyncKeyState_(#VK_LBUTTON) & 32768
If leftMouseFlag = 1
If leftMouseTicks < totalTicks
Debug "left clicked"
SendNetworkString(tempClient,"SIM|LEFTCLICK")
Else
Debug "left released"
SendNetworkString(tempClient,"SIM|ENDDRAG")
EndIf
leftMouseFlag = 0
leftMouseTicks = 0
leftMousePressed = 0
EndIf
EndIf
If GetAsyncKeyState_(#VK_LBUTTON) & 32768
rightMouseTicks = rightMouseTicks + 1
rightMouseFlag = 1
If rightMouseTicks >= totalTicks And rightMousePressed = 0
;Debug "right pressed"
rightMousePressed = 1
EndIf
EndIf
If Not GetAsyncKeyState_(#VK_LBUTTON) & 32768
If rightMouseFlag = 1
If rightMouseTicks < totalTicks
;Debug "right clicked"
SendNetworkString(tempClient,"SIM|RIGHTCLICK")
Else
;Debug "right released"
EndIf
rightMouseFlag = 0
rightMouseTicks = 0
rightMousePressed = 0
EndIf
EndIf
SEvent = NetworkServerEvent()
If SEvent
TheSever = EventServer()
ClientID = EventClient()
ClientIP = GetClientIP(ClientID)
Select SEvent
Case #PB_NetworkEvent_Connect ;Client connected
Case #PB_NetworkEvent_Data ;Raw data received
;A new client has connected, so add him to the client list
If ClientID <> tempClient
ReceiveNetworkData(ClientID,Buffer,5000)
AddGadgetItem(#clientList,-1,PeekS(Buffer)+Chr(10)+Str(ClientID))
EndIf
Case #PB_NetworkEvent_File ;File received
Case #PB_NetworkEvent_Disconnect ;Client disconnected
EndSelect
FreeMemory(Buffer)
Buffer = AllocateMemory(5000)
EndIf
DisplaySprite(windowSprite,0,0)
;ExamineMouse()
;DisplayTransparentSprite(mouseSprite,MouseX(),MouseY())
FlipBuffers()
ExamineKeyboard()
Delay(10)
Until KeyboardPushed(#PB_Key_Grave) And KeyboardPushed(#PB_Key_Escape)
FreeSprite(windowSprite)
;FreeSprite(mouseSprite)
CloseScreen()
ShowCursor_(0)
UnhookWindowsHookEx_(KeyboardHook)
SendNetworkString(tempClient,"OFF|ControlOff")
EndIf