Page 1 of 1

Keyboard Lights

Posted: Sat Jan 17, 2004 10:50 am
by Bong-Mong
Can i control the 3 lights on my keyboard
Num.
Scroll.
Caps.

here it is.

Posted: Sat Jan 17, 2004 11:52 am
by thefool
Here it is. Found on thread:
viewtopic.php?t=4130&highlight=numlock

Try to use the search button. I always get that response. But ok. The code
in the thread was messy to copy because it was not in the code blocks.
Here it is to copy and paste. Written by PB! I just formatted it. Sorry if you
get angry of me copying your code, pb :oops:

here:

Code: Select all

Procedure SetLEDKey(key$,newstate)
 Select LCase(key$)
  Case "c" : keycode=#VK_CAPITAL : oldstate=GetKeyState_(keycode)
  Case "n" : keycode=#VK_NUMLOCK : oldstate=GetKeyState_(keycode)
  Case "s" : keycode=#VK_SCROLL : oldstate=GetKeyState_(keycode)
 EndSelect
 If oldstate<>newstate
  keybd_event_(keycode,0,0,0)
  keybd_event_(keycode,0,#KEYEVENTF_KEYUP,0)
 EndIf
EndProcedure
;
SetLEDKey("c",1) ; Caps Lock on.
SetLEDKey("c",0) ; Caps Lock off.
;
SetLEDKey("n",1) ; Num Lock on.
SetLEDKey("n",0) ; Num Lock off.
;
SetLEDKey("s",1) ; Scroll Lock on.
SetLEDKey("s",0) ; Scroll Lock off.
It works. You just take the procedure, and looks at the examples.

Posted: Tue Mar 16, 2004 9:33 am
by dagcrack
This:

Code: Select all

  

Procedure SetLEDKey(key$,newstate) 
Select LCase(key$) 
  Case "c" : keycode=#VK_CAPITAL : oldstate=GetKeyState_(keycode) 
  Case "n" : keycode=#VK_NUMLOCK : oldstate=GetKeyState_(keycode) 
  Case "s" : keycode=#VK_SCROLL : oldstate=GetKeyState_(keycode) 
EndSelect 
If oldstate<>newstate 
  keybd_event_(keycode,0,0,0) 
  keybd_event_(keycode,0,#KEYEVENTF_KEYUP,0) 
EndIf 
EndProcedure 



Repeat
  
  SetLEDKey("n",1) : Delay(170) : SetLEDKey("n",0) ;num
  SetLEDKey("c",1) : Delay(170) : SetLEDKey("c",0) ;caps
  SetLEDKey("s",1) : Delay(170) : SetLEDKey("s",0) ;scroll

Until #PB_EventCloseWindow
Reminds me a car..
And this.. even.. more! http://www.gushh.com.ar/dls/cochefantastico.mid

Posted: Tue Mar 16, 2004 2:43 pm
by NoahPhense

Code: Select all

Procedure SetLEDKey(key$,newstate) 
Select LCase(key$) 
  Case "c" : keycode=#VK_CAPITAL : oldstate=GetKeyState_(keycode) 
  Case "n" : keycode=#VK_NUMLOCK : oldstate=GetKeyState_(keycode) 
  Case "s" : keycode=#VK_SCROLL : oldstate=GetKeyState_(keycode) 
EndSelect 
If oldstate<>newstate 
  keybd_event_(keycode,0,0,0) 
  keybd_event_(keycode,0,#KEYEVENTF_KEYUP,0) 
EndIf 
EndProcedure 



Repeat 
  
  SetLEDKey("n",1) : Delay(100) : SetLEDKey("n",0) ;num 
  SetLEDKey("c",1) : Delay(100) : SetLEDKey("c",0) ;caps 
  SetLEDKey("s",1) : Delay(100) : SetLEDKey("s",0) ;scroll
  SetLEDKey("c",1) : Delay(100) : SetLEDKey("c",0) ;caps 
  SetLEDKey("n",1) : Delay(100) : SetLEDKey("n",0) ;num 

  For x = 1 To 100 ; cHanGe THiS to 100000 Or SOmEtHiNg, AnD PUt IT
  ; In sOmEONes stART uP fOldER, OR hIDe iT And puT it In their rEGiStRy ;)
  ; tHIs IS WhAt hAPPenS  whILes iT rUNniNg.. Lol 
    SetLEDKey("c",1) : Delay(100) : SetLEDKey("c",0) ;caps 
    SetLEDKey("s",1) : Delay(100) : SetLEDKey("s",0) ;scroll
    SetLEDKey("c",1) : Delay(100) : SetLEDKey("c",0) ;caps 
    SetLEDKey("n",1) : Delay(100) : SetLEDKey("n",0) ;num 
  Next x

Until #PB_EventCloseWindow
 

End
lol

- np

Re: here it is.

Posted: Wed Mar 17, 2004 2:47 am
by PB
> The code in the thread was messy to copy because it was not in the
> code blocks.

In the old PureBasic forums, we didn't have code blocks, which is why a
lot of old snippets here are not formatted. The posts were just copied
directly over to these forums -- without formatting, as expected. :)

> I just formatted it. Sorry if you get angry of me copying your code, pb

It's okay -- you gave credit where it's due, which is the right way to quote. ;)

Posted: Wed Mar 17, 2004 4:01 am
by dagcrack
LOL!! hey heres the final one: http://www.gushh.com.ar/dls/f-led.zip hahahah.. Now.. gotta find the movie.

Posted: Wed Mar 17, 2004 5:05 am
by WolfgangS
dagcrack wrote:LOL!! hey heres the final one: http://www.gushh.com.ar/dls/f-led.zip hahahah.. Now.. gotta find the movie.
Excellent :lol: :wink:

MfG
WOlFGaNgs

Posted: Thu Apr 15, 2004 1:12 pm
by dagcrack
heh... thx :? :D

Posted: Fri Apr 16, 2004 12:20 pm
by Soulfire
This one is more fun :D
I ran into strangeness with GetKeyState() when performed in the loop, it seemed to give false values.. So I just keep track of the key states myself so that when the program is done, the keys are returned to the state that they were in before the program started.

Code: Select all

Global LED_KeyNum
Global LED_KeyCaps
Global LED_KeyScroll

; Save original states
OldNum    = GetKeyState_(#VK_NUMLOCK)
OldCaps   = GetKeyState_(#VK_CAPITAL)
OldScroll = GetKeyState_(#VK_SCROLL)

LED_KeyNum    = OldNum
LED_KeyCaps   = OldCaps
LED_KeyScroll = OldScroll

Procedure SetLEDKey(Key$,NewState)
  Key$ = LCase(Key$)
  Select Key$
    Case "n": KeyCode=#VK_NUMLOCK : OldState = LED_KeyNum
    Case "c": KeyCode=#VK_CAPITAL : OldState = LED_KeyCaps
    Case "s": KeyCode=#VK_SCROLL  : OldState = LED_KeyScroll
  EndSelect
  
  ;Debug "  oldstate: "+ Str(OldState)
  ;Debug "  newstate: "+ Str(NewState)
  
  If OldState <> NewState
    Select Key$
      Case "n": LED_KeyNum    = (1 - LED_KeyNum)
      Case "c": LED_KeyCaps   = (1 - LED_KeyCaps)
      Case "s": LED_KeyScroll = (1 - LED_KeyScroll)
    EndSelect
    
    keybd_event_(KeyCode,0,0,0) 
    keybd_event_(KeyCode,0,#KEYEVENTF_KEYUP,0) 
  EndIf 
  ;Debug "  currentstate: "+ Str(GetKeyState_(KeyCode))
EndProcedure

KeyNum    = OldNum
KeyCaps   = OldCaps
KeyScroll = OldScroll

For Index = 1 To 1000
  Key = Random(2)
  Select Key
    Case 0: KeyNum    = (1 - KeyNum)    : SetLEDKey("n",KeyNum)    ;num
    Case 1: KeyCaps   = (1 - KeyCaps)   : SetLEDKey("c",KeyCaps)   ;caps 
    Case 2: KeyScroll = (1 - KeyScroll) : SetLEDKey("s",KeyScroll) ;scroll 
  EndSelect
  
  Frequency = Random(1500) + 500
  Duration  = Random(100) + 15
  
  Beep_(Frequency,Duration)
  
  ;Delay(25)
Next

; Restore original states
SetLEDKey("n",OldNum)
SetLEDKey("c",OldCaps)
SetLEDKey("s",OldScroll)
Delay(25)

End