Logitech G15 u. G19 EasyAccess

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
SoS
Beiträge: 340
Registriert: 29.08.2004 09:31
Kontaktdaten:

Re: Logitech G15 u. G19 EasyAccess

Beitrag von SoS »

Bisonte hat geschrieben:Nunja ich hab mit PBx86 angenommen, auch die x86 DLL nutzen zu müssen, egal ob es auf x64 Win läuft oder nicht.
Ich bin logischerweise genaso vorgegangen. :)
Das ist aber nicht das 1. mal das ich dieses Verhalten feststellen musste, mit der libssh2.dll
gibt es genau das selbe Problem.
Ist das vieleicht ein Bug von PB ? Sollte eigendlich machbar sein den Code unter Win 64 bit für
Win 32 bit zu compilieren,oder doch nicht ?

Edit
Das unter Win 64 bit compilierte Programm für Win 32 bit läuft auch unter
32 bit nicht,trotz passender dll.
Benutzeravatar
Bisonte
Beiträge: 2429
Registriert: 01.04.2007 20:18

Re: Logitech G15 u. G19 EasyAccess

Beitrag von Bisonte »

Bananenfreak hat geschrieben:Ähm, ich weiß nicht, ob das dazu passt, aber was ich festgestellt habe ist, dass eine mit PB kompilierte DLL (x86) NUR unter x86 funktioniert. Genauso verhält es sich mit den x64-DLLs. Weiß ja nicht, ich habe das auch schon bei einigen anderen DLLs bemerkt, ich glaube das ist einfach so.
Von dem her wäre:

2. PBx86 und x64.dll = IMA ;Doppelt Sinnfrei, warum sollte x86 mit x64 Sachen umgehen können? + Nr.3
3. PBx64 und x86.dll = Sinnfrei... ;An sich logisch, da x64 mit x86 umgehen kann, ABER eben nicht die richtige DLL ist.

Zusatz:
Mit unserer Engine3D.dll ist es genauso. x64 Programm braucht x64 DLL und x86 braucht x86 DLL. Anders kann die Umgebung nicht initialisiert werden.
Ist klar. Allerdings konnte ich bisher unter Win x64 mit der PBx86 auch die x86.dll's nutzen. Nur hier scheint das nicht zu gehen.
Wobei die dann kompilierten Programme auf x86 sowie x64 lauffähig waren. Es geht schliesslich nur um den aufrufenden Prozess. Also der
Prozess, der die dll verarbeitet.
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
Benutzeravatar
Bisonte
Beiträge: 2429
Registriert: 01.04.2007 20:18

Re: Logitech G15 u. G19 EasyAccess

Beitrag von Bisonte »

So. Nun hab ich das auch mit den Symbolen hinbekommen.
Hier nun mein "Ergebnis" mit der Bitte um ausprobieren ;)

Das Ganze ist für Windows (das Beispiel ist auf Win7 x64 und einer G19 getestet) und PB5.21 (Modul)
Anbei noch ein Thread, der ein Event an ein vorhandenes Window sendet, wenn ein Button gedrückt wurde.

Ich hoffe es ist relativ selbsterklärend...
Ansonsten gilt ! : Fragen und Verbesserungsvorschläge ... Her damit ;)

Code: Alles auswählen

DeclareModule LGSDK
  
  ;:- There is one event for the button
  ;:- here you have to change the enumeration start value
  ;:- if it troubles with your own...
  
  Enumeration #PB_Event_FirstCustomValue
    #LGSDK_Button
  EndEnumeration
  
  ;:- 
  ;:- Logitech Gaming LCD SDK V1.01 (Driver >8.50)
  ;:- Copyright (C) 2011-2012 Logitech. All rights reserved.
  ;:- 
  ;:- Supported Displays :
  ;:- Color LCD, resolution of 320 by 240 pixels, full RGBA : G19, G19s
  ;:- Monochrome LCD, resolution of 160 by 43 pixels        : G510, G13, G15v1, G15v2
  ;:- 
  ;:- no UDK functions. (Is someone using the UnReal Engine with PureBasic ???)
  ;:-   

  #LOGI_LCD_TYPE_MONO           = $00000001
  #LOGI_LCD_TYPE_COLOR          = $00000002
  
  #LOGI_LCD_MONO_BUTTON_0       = $00000001
  #LOGI_LCD_MONO_BUTTON_1       = $00000002
  #LOGI_LCD_MONO_BUTTON_2       = $00000004
  #LOGI_LCD_MONO_BUTTON_3       = $00000008
  
  #LOGI_LCD_COLOR_BUTTON_LEFT   = $00000100
  #LOGI_LCD_COLOR_BUTTON_RIGHT  = $00000200
  #LOGI_LCD_COLOR_BUTTON_OK     = $00000400
  #LOGI_LCD_COLOR_BUTTON_CANCEL = $00000800
  #LOGI_LCD_COLOR_BUTTON_UP     = $00001000
  #LOGI_LCD_COLOR_BUTTON_DOWN   = $00002000
  #LOGI_LCD_COLOR_BUTTON_MENU   = $00004000
  
  #LOGI_LCD_MONO_WIDTH          = 160
  #LOGI_LCD_MONO_HEIGHT         = 43
  #LOGI_LCD_COLOR_WIDTH         = 320
  #LOGI_LCD_COLOR_HEIGHT        = 240
  
  Declare LcdInit(AppName.s, lcdType.l = #LOGI_LCD_TYPE_COLOR | #LOGI_LCD_TYPE_MONO)
  Declare LcdIsButton(Button)
  Declare LcdUpdate()
  Declare LcdShutDown()
  Declare LcdSetBackground(Image)
  Declare LcdSetText(LineNumber, Text.s, Red = 255, Green = 255, Blue = 255)
  Declare LcdSetTitle(Text.s, Red = 255, Green = 255, Blue = 255)
  Declare LcdButtonInit(Window, Delay = 200)
  
EndDeclareModule
Module        LGSDK
  
  EnableExplicit

  Structure struct_lgsdk_data
    Init.i
    Color.i
    bCount.i
    thread.i
    halt.i
    tDelay.i
    Size.POINT
    Array BitMapArray.b(1)    
  EndStructure
    
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    Import "x64\LogitechLcd.lib"
      LogiLcdInit.b(appName.p-unicode, lcdType.l)                                                   As "?LogiLcdInit@@YA_NPEA_WH@Z"
      LogiLcdIsConnected.b(lcdType.l)                                                               As "?LogiLcdIsConnected@@YA_NH@Z"
      LogiLcdIsButtonPressed.b(button.l)                                                            As "?LogiLcdIsButtonPressed@@YA_NH@Z"
      LogiLcdUpdate()                                                                               As "?LogiLcdUpdate@@YAXXZ"  
      LogiLcdShutdown()                                                                             As "?LogiLcdShutdown@@YAXXZ"
      LogiLcdMonoSetBackground.b(*MonoBitMapArray)                                                  As "?LogiLcdMonoSetBackground@@YA_NQEAE@Z"
      LogiLcdMonoSetText.b(linenumber.l, text.p-Unicode)                                            As "?LogiLcdMonoSetText@@YA_NHPEA_W@Z"  
      LogiLcdColorSetBackground.b(*ColorBitMapArray)                                                As "?LogiLcdColorSetBackground@@YA_NQEAE@Z"
      LogiLcdColorSetTitle.b(text.p-Unicode, red.l = 255, green.l = 255, blue.l = 255)              As "?LogiLcdColorSetTitle@@YA_NPEA_WHHH@Z"
      LogiLcdColorSetText.b(lineNumber.l, text.p-Unicode, red.l = 255, green.l = 255, blue.l = 255) As "?LogiLcdColorSetText@@YA_NHPEA_WHHH@Z"
    EndImport
  CompilerElse
    Import "x86\LogitechLcd.lib"
      LogiLcdInit.b(appName.p-unicode, lcdType.l)                                                   As "?LogiLcdInit@@YA_NPA_WH@Z"
      LogiLcdIsConnected.b(lcdType.l)                                                               As "?LogiLcdIsConnected@@YA_NH@Z"
      LogiLcdIsButtonPressed.b(button.l)                                                            As "?LogiLcdIsButtonPressed@@YA_NH@Z"
      LogiLcdUpdate()                                                                               As "?LogiLcdUpdate@@YAXXZ"  
      LogiLcdShutdown()                                                                             As "?LogiLcdShutdown@@YAXXZ"
      LogiLcdMonoSetBackground.b(*MonoBitMapArray)                                                  As "?LogiLcdMonoSetBackground@@YA_NQAE@Z"
      LogiLcdMonoSetText.b(linenumber.l, text.p-Unicode)                                            As "?LogiLcdMonoSetText@@YA_NHPA_W@Z"  
      LogiLcdColorSetBackground.b(*ColorBitMapArray)                                                As "?LogiLcdColorSetBackground@@YA_NQAE@Z"
      LogiLcdColorSetTitle.b(text.p-Unicode, red.l = 255, green.l = 255, blue.l = 255)              As "?LogiLcdColorSetTitle@@YA_NPA_WHHH@Z"
      LogiLcdColorSetText.b(lineNumber.l, text.p-Unicode, red.l = 255, green.l = 255, blue.l = 255) As "?LogiLcdColorSetText@@YA_NHPA_WHHH@Z"      
    EndImport           
  CompilerEndIf
  
  Global LogiLcd.struct_lgsdk_data
    
  Procedure LcdInit(AppName.s, lcdType.l = #LOGI_LCD_TYPE_COLOR | #LOGI_LCD_TYPE_MONO)
    
    Protected Result.b = #False

    Result = LogiLcdInit(AppName, lcdType)
    
    If Result
      If LogiLcdIsConnected(#LOGI_LCD_TYPE_COLOR)
        LogiLcd\Color   = #True
        LogiLcd\bCount  = 32
        LogiLcd\Size\x  = #LOGI_LCD_COLOR_WIDTH
        LogiLcd\Size\y  = #LOGI_LCD_COLOR_HEIGHT
        Dim LogiLcd\BitMapArray(#LOGI_LCD_COLOR_WIDTH * #LOGI_LCD_COLOR_HEIGHT * 4)
      ElseIf LogiLcdIsConnected(#LOGI_LCD_TYPE_MONO)
        LogiLcd\Color = #False
        LogiLcd\bCount  = 8
        LogiLcd\Size\x  = #LOGI_LCD_MONO_WIDTH
        LogiLcd\Size\y  = #LOGI_LCD_MONO_HEIGHT
        Dim LogiLcd\BitMapArray(#LOGI_LCD_MONO_WIDTH * #LOGI_LCD_MONO_HEIGHT)
      EndIf
      LogiLcd\Init = #True
    Else
      CompilerIf #PB_Compiler_Debugger
        Debug "LcdInit : Could not connect display!"
      CompilerElse
        MessageRequester("Error", "Could not connect display !")
      CompilerEndIf
    EndIf
        
    ProcedureReturn LogiLcd\Init
       
  EndProcedure
  Procedure LcdIsButton(Button)
    Protected Result = #False
    If LogiLcd\Init
      Result = LogiLcdIsButtonPressed(Button) - Button
    EndIf
    ProcedureReturn Result
  EndProcedure  
  Procedure LcdUpdate()
    If LogiLcd\Init
      LogiLcdUpdate()
    EndIf
  EndProcedure
  Procedure LcdShutDown()
    If LogiLcd\Init
      If IsThread(LogiLcd\thread)
        LogiLcd\halt = #True
        WaitThread(LogiLcd\thread)
        LogiLcd\thread = #False
      EndIf
      LogiLcdShutdown()
      LogiLcd\Init  = #False
      LogiLcd\Color = #False
      LogiLcd\bCount  = 8
      LogiLcd\Size\x  = #LOGI_LCD_MONO_WIDTH
      LogiLcd\Size\y  = #LOGI_LCD_MONO_HEIGHT
      FreeArray(LogiLcd\BitMapArray())
    EndIf
  EndProcedure  
  
  Procedure LcdButtonThread(Window)
    
    If LogiLcd\Init
      
      Repeat

        If LogiLcd\halt = #True
          Break 
        EndIf
        
        If IsWindow(Window)
          
          If LogiLcd\Color = #False
            
            If LcdIsButton(#LOGI_LCD_MONO_BUTTON_0)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_MONO_BUTTON_0)
            ElseIf LcdIsButton(#LOGI_LCD_MONO_BUTTON_1)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_MONO_BUTTON_1)
            ElseIf LcdIsButton(#LOGI_LCD_MONO_BUTTON_2)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_MONO_BUTTON_2)
            ElseIf LcdIsButton(#LOGI_LCD_MONO_BUTTON_3)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_MONO_BUTTON_3)
            EndIf
            
          Else
            
            If LcdIsButton(#LOGI_LCD_COLOR_BUTTON_LEFT)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_COLOR_BUTTON_LEFT)
            ElseIf LcdIsButton(#LOGI_LCD_COLOR_BUTTON_RIGHT)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_COLOR_BUTTON_RIGHT)
            ElseIf LcdIsButton(#LOGI_LCD_COLOR_BUTTON_OK)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_COLOR_BUTTON_OK)
            ElseIf LcdIsButton(#LOGI_LCD_COLOR_BUTTON_CANCEL)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_COLOR_BUTTON_CANCEL)
            ElseIf LcdIsButton(#LOGI_LCD_COLOR_BUTTON_UP)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_COLOR_BUTTON_UP)
            ElseIf LcdIsButton(#LOGI_LCD_COLOR_BUTTON_DOWN)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_COLOR_BUTTON_DOWN)
            ElseIf LcdIsButton(#LOGI_LCD_COLOR_BUTTON_MENU)
              PostEvent(#LGSDK_Button, Window, #LOGI_LCD_COLOR_BUTTON_MENU)
            EndIf  
            
          EndIf
          
        EndIf

        Delay(LogiLcd\tDelay)
        
      ForEver
          
    EndIf
        
  EndProcedure  
  Procedure LcdButtonInit(Window, Delay = 200)
    If IsWindow(Window)
      If LogiLcd\Init
        If Not IsThread(LogiLcd\thread)
          LogiLcd\halt = #False
          LogiLcd\tDelay = Delay
          LogiLcd\thread = CreateThread(@LcdButtonThread(), Window)
        EndIf
      EndIf
    EndIf
  EndProcedure
  
  Procedure LcdSetBackground(Image)
    
    Protected hDC, i, Result, Mono = #LOGI_LCD_MONO_WIDTH * #LOGI_LCD_MONO_HEIGHT
    Protected BMINFO.BITMAPINFO
    
    If Not LogiLcd\Init : ProcedureReturn #False : EndIf
    If Not IsImage(Image) : ProcedureReturn #False : EndIf
    
    If LogiLcd\Size\x <> ImageWidth(Image) Or LogiLcd\Size\y <> ImageHeight(Image)
      ResizeImage(Image, LogiLcd\Size\x, LogiLcd\Size\y)
    EndIf
    
    BMINFO\bmiHeader\biSize         = SizeOf(BITMAPINFO)
    BMINFO\bmiheader\biWidth        = LogiLcd\Size\x
    BMINFO\bmiheader\biHeight       = -(LogiLcd\Size\y)
    BMINFO\bmiheader\biPlanes       = 1
    BMINFO\bmiheader\biCompression  = #BI_RGB
    BMINFO\bmiheader\biBitCount     = LogiLcd\bCount
    
    hDC = StartDrawing(ImageOutput(Image))
    
    If hDC
      Result = GetDIBits_(hDC, ImageID(Image), 0, LogiLcd\Size\y, @LogiLcd\BitMapArray(), @BMINFO, #DIB_RGB_COLORS)
      
      ; Ist das hier so richtig fuer Mono Display ?
      If LogiLcd\Color = #False
        For i = 0 To Mono
          LogiLcd\BitMapArray(i) = LogiLcd\BitMapArray(i) ! $FF
        Next i
      EndIf
      
      If Result 
        If LogiLcd\Color
          LogiLcdColorSetBackground(@LogiLcd\BitMapArray())
        Else
          LogiLcdMonoSetBackground(@LogiLcd\BitMapArray())
        EndIf
      EndIf
      
      StopDrawing()
      
    EndIf
    
  EndProcedure
  Procedure LcdSetText(LineNumber, Text.s, Red = 255, Green = 255, Blue = 255)
    Protected Result.b = #False
    If LogiLcd\Init
      If LogiLcd\Color
        If LineNumber => 0 And LineNumber <= 7
          Result = LogiLcdColorSetText(LineNumber, Text, Red, Green, Blue)
        EndIf
      Else
        If LineNumber => 0 And LineNumber <= 3
          Result = LogiLcdMonoSetText(LineNumber, Text)
        EndIf
      EndIf
    EndIf
    ProcedureReturn Result
  EndProcedure
  Procedure LcdSetTitle(Text.s, Red = 255, Green = 255, Blue = 255)
    
    Protected Result.b = #False
    
    If LogiLcd\Init
      If LogiLcd\Color
        Result = LogiLcdColorSetTitle(Text, Red, Green, Blue)
      EndIf
    EndIf
    
    ProcedureReturn Result
    
  EndProcedure  
  
EndModule

CompilerIf #PB_Compiler_IsMainFile

  Image = CreateImage(#PB_Any, LGSDK::#LOGI_LCD_COLOR_WIDTH, LGSDK::#LOGI_LCD_COLOR_HEIGHT, 32)
  
  If StartDrawing(ImageOutput(Image))
    Box(0,50,OutputWidth(), 20, #Red)
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(10, 51, "Hello World !", #White)
    StopDrawing()
  EndIf
  
  Text.s = "": OldText.s = ""
    
  If OpenWindow(0, 0, 0, 0, 0, "Logitech G19 Applet Demo (PBx64 on Win7-x64)", #PB_Window_Invisible)
    
    If LGSDK::LcdInit("G19 Demo")
      
      LGSDK::LcdUpdate()
      LGSDK::LcdSetBackground(Image)
      
      LGSDK::LcdButtonInit(0, 200)
      
      Repeat
        
        Event = WaitWindowEvent(25)
        Text = ""
        
        If Event = #PB_Event_CloseWindow
          Quit = 1
        EndIf
        
        Select Event
          Case #PB_Event_CloseWindow
            Quit = 1
            
          Case LGSDK::#LGSDK_Button
            
            Select EventGadget()
              Case LGSDK::#LOGI_LCD_COLOR_BUTTON_MENU
                text = "you pressed : Menu"
              Case LGSDK::#LOGI_LCD_COLOR_BUTTON_OK
                text = "you pressed : Ok"
              Case LGSDK::#LOGI_LCD_MONO_BUTTON_0
                text = "you pressed : Button 0"
              Case LGSDK::#LOGI_LCD_MONO_BUTTON_1
                text = "you pressed : Button 1"
            EndSelect
            
            If StartDrawing(ImageOutput(Image))
              Box(0,0,OutputWidth(),OutputHeight(),0)
              Box(0,50,OutputWidth(), 20, #Red)
              DrawingMode(#PB_2DDrawing_Transparent)
              DrawText(10, 51, "Hello World !", #White)
              If Text <> ""
                DrawText(10, 71, Text, $cccccc)
              EndIf
              StopDrawing()
            EndIf
            If Text <> OldText
              OldText = Text
              LGSDK::LcdSetBackground(Image)            
            EndIf

        EndSelect
        
        LGSDK::LcdUpdate()
        
      Until Quit > 0
      
      LGSDK::LcdShutDown()
      
      CloseWindow(0)
      End
      
    EndIf
    
  EndIf
  
CompilerEndIf
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
Benutzeravatar
HeX0R
Beiträge: 2958
Registriert: 10.09.2004 09:59
Computerausstattung: AMD Ryzen 7 5800X
96Gig Ram
NVIDIA GEFORCE RTX 3060TI/8Gig
Win10 64Bit
G19 Tastatur
2x 24" + 1x27" Monitore
Glorious O Wireless Maus
PB 3.x-PB 6.x
Oculus Quest 2
Kontaktdaten:

Re: Logitech G15 u. G19 EasyAccess

Beitrag von HeX0R »

Ich habe mich mal aufgerafft und meinen alten Quark auf das aktuelle SDK angepasst.
Im Prinzip ist alles so ähnlich wie von Bisonte, allerdings habe ich den Import nie richtig hinbekommen, daher nehme ich einfach die DLL.
Benutzeravatar
HeX0R
Beiträge: 2958
Registriert: 10.09.2004 09:59
Computerausstattung: AMD Ryzen 7 5800X
96Gig Ram
NVIDIA GEFORCE RTX 3060TI/8Gig
Win10 64Bit
G19 Tastatur
2x 24" + 1x27" Monitore
Glorious O Wireless Maus
PB 3.x-PB 6.x
Oculus Quest 2
Kontaktdaten:

Re: Logitech G15 u. G19 EasyAccess

Beitrag von HeX0R »

Hier noch ein kleines Include zum direkten Nutzen der G-Tasten (Windows only):

Code: Alles auswählen

;/---------------------------------
;|
;| G15_G19_GKeys.pbi V1.00
;|
;| Include for using the Gxx keys of a
;| Logitech G15/G19 Keyboard
;|
;| Source: https://www.purebasic.fr/german/viewtopic.php?p=349911#p349911
;|
;| (c)HeX0R 2018
;/---------------------------------

#LOGITECH_MAX_MOUSE_BUTTONS = 20
#LOGITECH_MAX_GKEYS         = 29
#LOGITECH_MAX_M_STATES      = 3

Structure GKeyCode
	keyIdx.i         ;index of the G key or mouse button, for example, 6 for G6 or Button 6
	keyDown.i        ;key up or down, 1 is down, 0 is up
	mState.i         ;mState (1, 2 or 3 for M1, M2 and M3)
	mouse.i          ;indicate if the Event comes from a mouse, 1 is yes, 0 is no.
EndStructure


DeclareModule LOGIGKEYS
	
	Structure GKeyCode
		keyIdx.i
		keyDown.i
		mState.i
		mouse.i
	EndStructure
	
	Declare Init(*CallBack, *Context = 0)
	Declare IsMousePressed(ButtonNumber.i)
	Declare IsGKeyPressed(gKeyNumber.i, modeNumber.i)
	Declare.s GetMouseButtonString(ButtonNumber.i)
	Declare.s GetGKeyString(gKeyNumber.i, modeNumber.i)
	Declare GetKeyCodes(gKeyCode.l, *KeyCodes.GKeyCode)
	Declare ShutDown()
	
	
EndDeclareModule

Module LOGIGKEYS
	
	Structure logiGKeyCBContext
		*gkeyCallBack
		*gkeyContext
	EndStructure
	
	PrototypeC.i LogiGkeyInit(*Context.logiGKeyCBContext)
	PrototypeC.i LogiGkeyIsMouseButtonPressed(buttonNumber.i)
	PrototypeC.i LogiGkeyGetMouseButtonString(buttonNumber.i)
	PrototypeC.i LogiGkeyIsKeyboardGkeyPressed(gKeyNumber.i, ModeNumber.i)
	PrototypeC.i LogiGkeyGetKeyboardGkeyString(gKeyNumber.i, ModeNumber.i)
	PrototypeC LogiGkeyShutdown()
	
	Global DLL, PATH2DLL.s

	Global LogiGkeyInit.LogiGkeyInit
	Global LogiGkeyShutdown.LogiGkeyShutdown
	Global LogiGkeyIsMouseButtonPressed.LogiGkeyIsMouseButtonPressed
	Global LogiGkeyGetMouseButtonString.LogiGkeyGetMouseButtonString
	Global LogiGkeyIsKeyboardGkeyPressed.LogiGkeyIsKeyboardGkeyPressed
	Global LogiGkeyGetKeyboardGkeyString.LogiGkeyGetKeyboardGkeyString
	
	Procedure.s GetDLLPath()
		Protected Result.s, PATH.s, hKey, lpcbData, *lpData, lpType
	
		CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
			PATH = "SOFTWARE\Classes\WOW6432Node\CLSID\{7bded654-f278-4977-a20f-6e72a0d07859}\ServerBinary"
		CompilerElse
			PATH = "SOFTWARE\Classes\CLSID\{7bded654-f278-4977-a20f-6e72a0d07859}\ServerBinary"
		CompilerEndIf
	
		If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, PATH, 0, #KEY_READ, @hKey) = #ERROR_SUCCESS
			If RegQueryValueEx_(hKey, "", 0, 0, 0, @lpcbData) = #ERROR_SUCCESS
				*lpData = AllocateMemory(lpcbData)
				If *lpData
					If RegQueryValueEx_(hKey, "", 0, @lpType, *lpData, @lpcbData) = #ERROR_SUCCESS
						Result = PeekS(*lpData)
					EndIf
					FreeMemory(*lpData)
				EndIf
			EndIf
			RegCloseKey_(hKey)
		EndIf
	
		ProcedureReturn Result
	EndProcedure
		
	Procedure Init(*CallBack, *Context = 0)
		Protected i, *C, Result
		Protected GKeyCBContext.logiGKeyCBContext
		
		If DLL
			CloseLibrary(DLL)
		EndIf
		
		PATH2DLL = GetDLLPath()
		If PATH2DLL = ""
			ProcedureReturn #False
		EndIf
		
		DLL = OpenLibrary(#PB_Any, PATH2DLL)
		If DLL = 0
			ProcedureReturn #False
		EndIf
		
		GKeyCBContext\gkeyContext  = *Context
		GKeyCBContext\gkeyCallBack = *CallBack
		
		LogiGkeyInit                  = GetFunction(DLL, "LogiGkeyInit")
		LogiGkeyShutdown              = GetFunction(DLL, "LogiGkeyShutdown")
		LogiGkeyIsMouseButtonPressed  = GetFunction(DLL, "LogiGkeyIsMouseButtonPressed")
		LogiGkeyGetMouseButtonString  = GetFunction(DLL, "LogiGkeyGetMouseButtonString")
		LogiGkeyIsKeyboardGkeyPressed = GetFunction(DLL, "LogiGkeyIsKeyboardGkeyPressed")
		LogiGkeyGetKeyboardGkeyString = GetFunction(DLL, "LogiGkeyGetKeyboardGkeyString")
		
		If LogiGkeyInit And LogiGkeyShutdown And LogiGkeyIsMouseButtonPressed And LogiGkeyGetMouseButtonString And LogiGkeyIsKeyboardGkeyPressed And LogiGkeyGetKeyboardGkeyString
			Result = LogiGkeyInit(@GKeyCBContext)
		EndIf
		If Result = #False
			CloseLibrary(DLL)
			DLL = #False
		EndIf
		
		ProcedureReturn Result
	EndProcedure
	
	
	Procedure ShutDown()
		
		If DLL
			LogiGkeyShutdown()
			CloseLibrary(DLL)
			DLL = #False
		EndIf
		
		
	EndProcedure
	
	Procedure IsGKeyPressed(gKeyNumber.i, modeNumber.i)
		Protected Result
		
		If DLL
			Result = LogiGkeyIsKeyboardGkeyPressed(gKeyNumber, modeNumber)
		EndIf
		
		ProcedureReturn Result
	EndProcedure
	
	Procedure IsMousePressed(ButtonNumber.i)
		Protected Result
		
		If DLL
			Result = LogiGkeyIsMouseButtonPressed(ButtonNumber)
		EndIf
		
		ProcedureReturn Result
	EndProcedure
	
	Procedure.s GetMouseButtonString(ButtonNumber.i)
		Protected Result.s, *Pointer
		
		If DLL
			*Pointer = LogiGkeyGetMouseButtonString(ButtonNumber)
			If *Pointer
				Result = PeekS(*Pointer)
			EndIf
		EndIf
		
		ProcedureReturn Result
	EndProcedure
	
	Procedure.s GetGKeyString(gKeyNumber.i, modeNumber.i)
		Protected Result.s, *Pointer
		
		If DLL
			*Pointer = LogiGkeyGetKeyboardGkeyString(gKeyNumber, modeNumber)
			If *Pointer
				Result = PeekS(*Pointer)
			EndIf
		EndIf
		
		ProcedureReturn Result
	EndProcedure
	
	Procedure GetKeyCodes(gKeyCode.l, *KeyCodes.GKeyCode)
		
		If *KeyCodes
			*KeyCodes\keyIdx = GKeyCode & $FF
			GKeyCode >> 8
			*KeyCodes\keyDown = GKeyCode & 1
			GKeyCode >> 1
			*KeyCodes\mState = GKeyCode & 3
			GKeyCode >> 2
			*KeyCodes\mouse = GKeyCode & 1
		EndIf
		
	EndProcedure

EndModule


;------------------------
CompilerIf #PB_Compiler_IsMainFile
	
	ProcedureC CallBack(gKeyCode.l, gKeyOrButtonString.s, *Context)
		Protected KC.GKeyCode, a$
		
		LOGIGKEYS::GetKeyCodes(gKeyCode, @KC)
		
		a$ = "G" + Str(KC\keyIdx)
		If KC\keyDown
			a$ + " pressed!"
		Else
			a$ + " released!"
		EndIf
		a$ + "; belongs to M" + Str(KC\mState)
		If KC\mouse
			a$ + "; came from mouse!"
		Else
			a$ + "; via Keyboard!"
		EndIf
		a$ + "; Friendly Name: " + gKeyOrButtonString
		AddGadgetItem(0, -1, a$)
		
	EndProcedure
	
	Procedure main()
		Protected i, j
	
		OpenWindow(0, 0, 0, 600, 300, "test")
		EditorGadget(0, 5, 5, 590, 290, #PB_Editor_ReadOnly)
	
		If LOGIGKEYS::Init(@CallBack())
			
			Debug LOGIGKEYS::GetGKeyString(1, 1)
			Debug LOGIGKEYS::GetGKeyString(2, 1)
			Debug LOGIGKEYS::GetMouseButtonString(1)
			Debug LOGIGKEYS::GetMouseButtonString(2)
			
			Repeat
			Until WaitWindowEvent() = #PB_Event_CloseWindow

	
			LOGIGKEYS::ShutDown()

		EndIf

	EndProcedure
	
	main()
	
CompilerEndIf
Antworten