[LIBRARY] WIH - Mouse & Keyboard Library [Windows x64]

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

[LIBRARY] WIH - Mouse & Keyboard Library [Windows x64]

Post by Mijikai »

WIH (Window Input Handler)
wih.lib is a small library to handle mouse and keyboard input.

Example:

Code: Select all

;WIH - WINDOW INPUT HANDLER 
;A SMALL LIBRARY TO HANDLE MOUSE AND KEYBOARD INPUT
;AUTHOR: MIJIKAI
;VERSION: 1.0

EnableExplicit

Import "wih.lib"
  wihCreate.i(hwnd.i)
EndImport

Interface WIH
  Focus.i()                       ;is the window focused / is the input attached to the window thread!
  Key.i(Code.i)                   ;is the key pushed? / use #VK key-codes
  KeySgl.i(Code.i)                ;was the key pushed? / use #VK key-codes 
  KeyChr.i()                      ;get the chr key code of the pushed key
  MouseCheck.i()                  ;is the mouse inside the client area of the window
  MouseLeft.i()                   ;is the left mouse button pushed?
  MouseRight.i()                  ;is the right mouse button pushed?
  MouseMiddle.i()                 ;is the middle mouse button pushed?
  MouseLeftSgl.i()                ;was the left mouse button pushed?
  MouseRightSgl.i()               ;was the right mouse button pushed?
  MouseMiddleSgl.i()              ;was the middle mouse button pushed?
  MouseLeftDbl.i()                ;was the left mouse button pushed twice in a short time? / doubleclick!
  MouseRightDbl.i()               ;was the right mouse button pushed twice in a short time? / doubleclick!
  MouseMiddleDbl.i()              ;was the middle mouse button pushed twice in a short time? / doubleclick!
  MouseWheel.i(Code.i = #Null)    ;was the mousewheel moved? / optional check if a special key is pressed!
  MouseX.i()                      ;get the mouse horizontal (x) postion / offset from the top left corner of the client area!
  MouseY.i()                      ;get the mouse verical (y) postion / offset from the top left corner of the client area!
  Flush.i()                       ;flush the input buffers / needed for all 'Sgl' and 'Dbl' functions to work properly!
  Release.i()                     ;release the input handler and all associated resources
EndInterface

Procedure.i Demo(Title.s = #Null$,Width.i = 600,Height.i = 400)
  Protected wnd.i
  Protected wnd_flags.i
  Protected wnd_event.i
  Protected wnd_exit.i
  Protected *input.WIH
  wnd_flags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
  wnd = OpenWindow(#PB_Any,#Null,#Null,Width,Height,Title,wnd_flags) 
  If wnd
    WindowBounds(wnd,Width,Height,#PB_Ignore,#PB_Ignore)
    *input = wihCreate(WindowID(wnd))
    If *input
      Repeat 
        Select WaitWindowEvent()
          Case #PB_Event_CloseWindow
            wnd_exit = #True
        EndSelect
        ;-------------------------------
        ;check mouse and keyboard input!
        If *input\MouseLeftDbl()
          Debug "DoubleClick!"
        EndIf
        ;-------------------------------
        *input\Flush();<- when done flush the input buffers!
      Until wnd_exit
      *input\Release();<- release all resources
    EndIf
    CloseWindow(wnd)
  EndIf
  ProcedureReturn #Null
EndProcedure

Demo("WIH")

End
Download:
https://www.dropbox.com/s/9bzqhhsb5iehn ... 0.zip?dl=0
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: [LIBRARY] WIH - Mouse & Keyboard Library [Windows x64]

Post by IdeasVacuum »

...but where is the library?

Ah! Linked to DropBox :mrgreen:
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply