@learner
There's no way to force the capslock on or off with standard DBC commands. However, you can use the win32 api to do it. The win api are commands that Windows uses to perform certain functions. Using some of these commnads, you can force keyboard input by programming it.
Though this may be a bit advanced, you access these commands by calling a DLL function. A DLL is a piece of machine executable code that has functions in it. You can call these functions through DBC. DLLs have the advantage of speed and extending the capabilities of DBC.
In the following example, I use the win api command
keybd_event which is found in the user32.dll DLL. This function sets a key down (pressed)or up (released).
Now because the CAPSLOCK state can be toggled - every time it's pressed it's either on or off, I have to check whether or not the keyboard is in CAPS mode. I do that using a combination keybd_event and the DBC command inkey$(). Inkey$() will return either a capital letter or a lowercase letter depending on the capslock state. I'll check this letter so I know if I should or shouldn't force the capslock to be pressed. After I'm done typing capitals, I then force another capslock press to toggle the keyboard state to lowercase. Here is the example:
rem caps on-off
rem by latch
rem 03/19/2009
rem load the win api dll that is needed and setup the constants
gosub _load_dll
rem test if caplocks are set
rem the keycode for the letter A is 65 so we'll test
rem using inkey$() to see if it comes out as a capital
a=65
keydown(a,user32)
wait 0
value=asc(inkey$())
rem release the A key
keyup(65,user32)
wait 0
rem if value is = to a, then the caps lock light is on (the caps lock key was
rem already pressed) That means we don't have to activate it
if value=a
rem do nothing
else
rem use the keybd_event function to force the caplocks key active
keydown(VK_CAPITAL,user32)
keyup(VK_CAPITAL,user32)
endif
input "Type some words : ";a$
print a$
print
print "Automatically turn caps off"
print
rem when done inputting as caps, turn the caps keystate off
keydown(VK_CAPITAL,user32)
keyup(VK_CAPITAL,user32)
input "Type some words : ";a$
print a$
end
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
_load_dll:
rem the dll info
user32=1
load dll "user32.dll",user32
rem the capslock key virtual key code
VK_CAPITAL = 20
return
rem =============================================================
rem = FUNCTIONS
rem =============================================================
function keydown(key,user32)
if key < 1 or key > 254
key = 1
endif
call dll user32,"keybd_event",key,0,0,0
endfunction
function keyup(key,user32)
KEYEVENTF_KEYUP = 2
call dll user32,"keybd_event",key,0,KEYEVENTF_KEYUP,0
endfunction
Enjoy your day.