PureBasic Forum
https://www.purebasic.fr/english/

[LIBRARY] WIH - Mouse & Keyboard Library [Windows x64]
https://www.purebasic.fr/english/viewtopic.php?f=27&t=74870
Page 1 of 1

Author:  Mijikai [ Sun Mar 15, 2020 11:34 am ]
Post subject:  [LIBRARY] WIH - Mouse & Keyboard Library [Windows x64]

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

Example:
Code:
;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/9bzqhhsb5iehnoz/wih_v1.0.zip?dl=0

Author:  IdeasVacuum [ Sun Mar 15, 2020 2:35 pm ]
Post subject:  Re: [LIBRARY] WIH - Mouse & Keyboard Library [Windows x64]

...but where is the library?

Ah! Linked to DropBox :mrgreen:

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/