Keyboard Monitor -> Free Fast Useful.

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
max_aigneraigner@web.de
User
User
Posts: 67
Joined: Sun Nov 02, 2008 10:37 pm
Location: Bavaria
Contact:

Keyboard Monitor -> Free Fast Useful.

Post by max_aigneraigner@web.de »

Hi guys,
I just wrote a small programm to display your keyboardinput.
I don't know wether it is bugfree or so... BUT
it is useful for example for tutorial videos. (for Blender etc.. then everyone can see your Keyboardinput OnScreen! )

codingtime... ok.. 10/15 minutes.. ^^
(I hope there is no such program in pb till now... I just haven't found anything..^^)

and here the code :

Code: Select all

;
; ... MIT Licence...you are free to do evrything.. 
; -----------------------------------------------------------------------------------
; -----------------------------------------------------------------------------------
; -- programmed by Aigner, Max (bavaria) 
; -- 22. Mai 2010
; -- 10:39 o'clock

; -----------------------------------------------------------------------------------
; -------------------------------------------------------------- Enumeration -------
; -----------------------------------------------------------------------------------

Enumeration
  #Window_tastaturanzeige
EndEnumeration

Enumeration
  #text_tastatureingabe
EndEnumeration

#ClearDelay = 180; Time until text will be erased.
#vk_oem_attn = $F0
; -----------------------------------------------------------------------------------
; -------------------------------------------------------------- STRUCTURES ----------
; -----------------------------------------------------------------------------------
Structure keylist
   EndTime.i ; in Milliseconds.. ;) 
   Keystring.s ; the String (text) of the key.. -> ESC
   keyid.i   ; the ID of the Key.  -> #vk_escape..
EndStructure 

; -----------------------------------------------------------------------------------
; -------------------------------------------------------------- Globals ------------
; -----------------------------------------------------------------------------------
;- Fonts
Global FontID1
FontID1 = LoadFont(1, "Courier New", 18, #PB_Font_Bold)
Global FontID2
FontID2 = LoadFont(2, "Courier New", 16)
Global FontID3
FontID3 = LoadFont(3, "Courier New", 16, #PB_Font_Bold)


; -----------------------------------------------------------------------------------
; -------------------------------------------------------------- Procedures  --------
; -----------------------------------------------------------------------------------

Macro DoubleQuote  ; macro, um Macros in strings zu ermöglichen.. z.B. Doublequote#hans#doublequote
    "
EndMacro


Macro getkey                  ( Key_  ); Macro um die Tasten alle abzufragen... 
   key.s = Doublequote#Key_#Doublequote 
   macro_getkey_text.s        = ""
   KeyLoaded                  = 0
   
   
   If key > ""
      If getasynckeystate_(#vk_#Key_)
        
         ForEach Keylist() ; checks, wether the key is already displayed or not.
            If Keylist()\keyid = #vk_#Key_
               KeyLoaded = 1
               Keylist()\EndTime = ElapsedMilliseconds() + #ClearDelay
               Break 
            EndIf 
         Next 
         
         If KeyLoaded = 0    ; If key has not been pressed before
               AddElement ( Keylist())
                  Keylist()\Keystring = key
                  Keylist()\keyid     = #vk_#Key_
                  Keylist()\EndTime = ElapsedMilliseconds() + #ClearDelay
         EndIf 
         
      EndIf 
   EndIf 
   
EndMacro 

Macro  DisplayAllKeys()
   
   ForEach Keylist()  ; replace wrong writing (in english: =spelling?..)..
      Select LCase( Keylist()\Keystring )
         Case "control"
            Keylist()\Keystring = "CTRL"
         Case "shift"
            Keylist()\Keystring = "SHIFT"
         Case "menu"
            Keylist()\Keystring = "ALT"
         Case "prior"
            Keylist()\Keystring = "Page Up"
         Case "next" ; page down
            Keylist()\Keystring = "Page Down"
         Case "escape"
            Keylist()\Keystring = "ESC"
         Case "numpad0"
            Keylist()\Keystring = "NUM0"
         Case "numpad1"
            Keylist()\Keystring = "NUM1"
         Case "numpad2"
            Keylist()\Keystring = "NUM2"
         Case "numpad3"
            Keylist()\Keystring = "NUM3"
         Case "numpad4"
            Keylist()\Keystring = "NUM4"
         Case "numpad5"
            Keylist()\Keystring = "NUM5"
         Case "numpad6"
            Keylist()\Keystring = "NUM6"
         Case "numpad7"
            Keylist()\Keystring = "NUM7"
         Case "numpad8"
            Keylist()\Keystring = "NUM8"
         Case "numpad9"
            Keylist()\Keystring = "NUM9"
         Case "lbutton"
            Keylist()\Keystring = "LMouse"
         Case "rbutton"
            Keylist()\Keystring = "RMouse"
         Case "mbutton"
            Keylist()\Keystring = "MMouse"
         Case "oem_period"
            Keylist()\Keystring = "Period" ; PUNKT! ;) 
         Case "oem_comma"
            Keylist()\Keystring = "Comma" ; komma..
         Case "oem_plus"
            Keylist()\Keystring = "Plus" ; komma..
         Case "oem_minus"
            Keylist()\Keystring = "Minus" ; komma..
      EndSelect 
   Next 
   
   ForEach Keylist()  
      keylistcounter + 1 
      getallkeys_output.s + Keylist()\Keystring 
      If keylistcounter < ListSize( Keylist())
         getallkeys_output + "+"
      EndIf 
      
      If Keylist()\EndTime < ElapsedMilliseconds()
         DeleteElement( Keylist())
      EndIf 
   Next 
   If Not getallkeys_output = GetGadgetText( #text_tastatureingabe) ; And Not getallkeys_output = ""
      SetGadgetText( #text_tastatureingabe , getallkeys_output )
   EndIf 
EndMacro 

Procedure getallkeys() ; prüft alle tasten ob sie gedrückt wurden..
   Protected  getallkeys_output.s , keylistcounter.i , KeyLoaded.i
   Static  NewList Keylist.keylist() ; can be static, then every pressed key will be there for 300 ms..
   
   getallkeys_IsKeyPressed = 0
   
   getkey(menu)
   getkey(Control)
   getkey(shift)
   getkey(print)
   getkey(pause)
   getkey( space) 
   getkey(tab)
   getkey( a ) 
   getkey( b ) 
   getkey( c ) 
   getkey( d ) 
   getkey( e ) 
   getkey( f ) 
   getkey( g ) 
   getkey( h ) 
   getkey( i ) 
   getkey( j ) 
   getkey( k ) 
   getkey( l ) 
   getkey( m ) 
   getkey( n ) 
   getkey( o ) 
   getkey( p ) 
   getkey( q ) 
   getkey( r ) 
   getkey( s ) 
   getkey( t ) 
   getkey( u ) 
   getkey( v ) 
   getkey( w ) 
   getkey( x ) 
   getkey( y ) 
   getkey( z ) 
   getkey( 1 ) 
   getkey( 2 ) 
   getkey( 3 ) 
   getkey( 4 )
   getkey( 5 )
   getkey( 6 ) 
   getkey( 7 )
   getkey( 8 )
   getkey( 9 ) 
   getkey( 0 ) 
   getkey( add )
   getkey( subtract)
   getkey( down )
   getkey( up )
   getkey( left)
   getkey( right)
   getkey( End )
   getkey( divide)
   getkey( multiply)
   getkey( escape)
   getkey( f1)
   getkey( f2)
   getkey( f3)
   getkey( f4)
   getkey( f5)
   getkey( f6)
   getkey( f7)
   getkey( f8)
   getkey( f9)
   getkey( f10)
   getkey( f11)
   getkey( f12)
   getkey( f13)
   getkey( f14)
   getkey( f15)
   getkey( f16)
   getkey( f17)
   getkey( f18)
   getkey( f19)
   getkey( f20) ; there are 24 function keys... for special function keyboards.
   getkey( f21)
   getkey( f22)
   getkey( f23)
   getkey( f24)
   getkey( home)
   getkey( help)
   getkey( lwin)
   getkey( rwin)
   getkey( mbutton)
   getkey( lbutton)
   getkey( rbutton)
   getkey( numlock)
   getkey( numpad0)
   getkey( numpad1)
   getkey( numpad2)
   getkey( numpad3)
   getkey( numpad4)
   getkey( numpad5)
   getkey( numpad6)
   getkey( numpad7)
   getkey( numpad8)
   getkey( numpad9)
   getkey( print)
   getkey( Return)
   getkey( volume_down)
   getkey( volume_up)
   getkey( zoom)
   getkey( delete)
   getkey( back)
   getkey( attn)
   getkey(snapshot)
   getkey( separator)
   getkey(scroll)
   getkey(PRIOR)
   getkey(play)
   getkey(Next)
   getkey(oem_period)
   getkey(oem_comma)
   getkey(oem_plus)
   getkey(oem_minus)
   getkey(oem_attn)
   getkey(capital)
   getkey(crsel)
   getkey(convert)
   getkey(ereof)
   getkey(insert)
   getkey(media_next_track)
   getkey(media_play_pause)
   getkey(media_prev_track)
   getkey(media_stop)
   getkey(packet)
   getkey(PRIOR)
   getkey(play)

   DisplayAllKeys() ; displays all keys..
EndProcedure 
#vk_oem_attn = $F0
Procedure Open_Window_tastaturanzeige()
  If OpenWindow(#Window_tastaturanzeige, 811, 342, 148, 56, "Gemusoft Tastatur",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_tastaturanzeige))
      TextGadget(#text_tastatureingabe, 0, 0, 550, 60, "")
      SetGadgetFont(#text_tastatureingabe, FontID3)
      StickyWindow( #Window_tastaturanzeige , 1 )
      
      Repeat 
         evt  = WaitWindowEvent(10)
         getallkeys()
         
         Select evt
            Case #PB_Event_Gadget
               
            Case #PB_Event_Menu
            
            Case #PB_Event_CloseWindow 
              End 
         EndSelect 
         
      ForEver 
    EndIf
  EndIf
EndProcedure

Open_Window_tastaturanzeige()
yours -> Max A. (Draufwalker)

EDIT..
so.. and now it works with Multiple Inputkeys :) YEAH! it feels so good to be back at PB-programming again :)
/edit
3D Projects
A ship is safest in the harbor, but that is not what ships are built for.
User avatar
singo
User
User
Posts: 35
Joined: Mon Apr 23, 2007 4:50 am
Location: Nabiac NSW Australia

Re: Keyboard Monitor -> Free Fast Useful.

Post by singo »

Thanks this is very useful :D
Singo
Win10, Win7, Debian x86 & OSX ~ PB 5.70 LTS
Minimbah NSW Australia
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Keyboard Monitor -> Free Fast Useful.

Post by walbus »

@Singo
Usefull for what ?
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Keyboard Monitor -> Free Fast Useful.

Post by Lunasole »

walbus wrote:Usefull for what ?
To diagnose your precious keyboard after it was washed up with coffee ^_^
At least I have similar utility for that.. nicely detects any key or mouse lags, also used it once to debug complicated stuff with input emulation
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Post Reply