Keyboard Lights

Windows specific forum
Bong-Mong
User
User
Posts: 35
Joined: Sat Jan 03, 2004 6:53 pm

Keyboard Lights

Post by Bong-Mong »

Can i control the 3 lights on my keyboard
Num.
Scroll.
Caps.
1.3AMD, 2x 256 sdr, 32 AGP
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

here it is.

Post 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.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post 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
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post 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
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: here it is.

Post 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. ;)
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

LOL!! hey heres the final one: http://www.gushh.com.ar/dls/f-led.zip hahahah.. Now.. gotta find the movie.
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post 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
WolfgangS' projects http://www.schliess.net
Quotation of the month:
<p3hicy>oder ich hol mir so eine geile aus asien
<p3hicy>die ständig poppen will
<p3hicy>'n brötchen pro tag reicht doch
<p3hicy>die essen eh' nich so viel
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

heh... thx :? :D
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Soulfire
User
User
Posts: 23
Joined: Mon Mar 08, 2004 7:17 am

Post 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
Post Reply