It is currently Sun Oct 13, 2019 10:01 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Keyboard Monitor -> Free Fast Useful.
PostPosted: Sat May 22, 2010 6:03 pm 
Offline
User
User
User avatar

Joined: Sun Nov 02, 2008 10:37 pm
Posts: 67
Location: Bavaria
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:
;
; ... 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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard Monitor -> Free Fast Useful.
PostPosted: Sun Jul 23, 2017 12:01 am 
Offline
User
User
User avatar

Joined: Mon Apr 23, 2007 4:50 am
Posts: 32
Location: Nabiac NSW Australia
Thanks this is very useful :D

_________________
Singo
Win10, Win7, Debian x86 & OSX ~ PB 5.70 LTS
Minimbah NSW Australia


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard Monitor -> Free Fast Useful.
PostPosted: Thu Jul 27, 2017 7:42 am 
Offline
Addict
Addict

Joined: Sat Mar 02, 2013 9:17 am
Posts: 931
@Singo
Usefull for what ?

_________________
http://www.nachtoptik.de


Top
 Profile  
Reply with quote  
 Post subject: Re: Keyboard Monitor -> Free Fast Useful.
PostPosted: Fri Jul 28, 2017 12:03 am 
Offline
Addict
Addict
User avatar

Joined: Mon Oct 26, 2015 2:55 am
Posts: 908
Location: UA
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

_________________
Dreamness

Like a copyleft notify: all the source code created by me and posted on Purebasic official forums is free to use and modification in all possible (and several impossible) ways for anyone, without asking my permission


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye