AllenAdministrator
(KiX Supporter)
2004-06-16 05:46 AM
Case-Sensitive Sendkeys() or Keystate()

I would like to see either an updated sendkeys function that sends the keys as they are actually typed in the script, not being effected by Capslock or Numlock, or as another suggestion, maybe a function like keystate(), which allows you to not only set the state of capslock and numlock, but also allow you to check it.

I'm aware the AutoIT has this functionality to some degree and I would consider this suggestion pretty low priority. However, it's something I have run across, and have seen other people asking about as well:
Check for CAPSLOCK
What is NumLock key status?

I have absolutely no idea how hard this would be to add, but I've found a few articles discussing how this is done in vb:

HOWTO Find Keystate of Numlock, Capslock etc., in VB
HOWTO: Toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK Keys



NTDOCAdministrator
(KiX Master)
2004-06-16 10:40 AM
Re: Case-Sensitive Sendkeys() or Keystate()

Hi Alpo

I know this is not what you're looking for exactly, but here are a couple files to toggle the state.

NumOn (Enable Numlock)
http://www.kixhelp.com/Downloads/numon.exe

NumOff (Disable Numlock)
http://www.kixhelp.com/Downloads/numoff.exe


AllenAdministrator
(KiX Supporter)
2004-06-22 04:00 AM
Re: Case-Sensitive Sendkeys() or Keystate()

I just found some code that supposedly set and checks the states of the numlock, capslock and scroll lock. The name of the file is keystate.bat and it looks very similiar to a batch file but its not... anyone have any ideas what might run this code?

Code:
 

@echo off
::~~~1 Set, unset, or display the state of keys NUMLOCK, CAPSLOCK or SCROLL keys.

SEDOS %0.bat %1 %2 %3 %4
GOTO SE_EXIT

#define NUMLOCK_BIT 0x20
#define CAPSLOCK_BIT 0x40
#define INSERT_BIT 0x80
#define KEYS_SEGMENT 0x0040
#define KEYS_OFFSET 0x0017
KeysAddress = Address(KEYS_SEGMENT,KEYS_OFFSET)

main(argc,argv)
{
// check that the input is valid
if ( argc != 3
|| ( argv[1][1] != 0 || !strchr("+?-",argv[1][0]) )
|| ( strnicmp("CAP",argv[2],3)
&& strnicmp("NUM",argv[2],3)
&& strnicmp("INS",argv[2],3) ) ) {
Instructions()
} else {
// determine whether to apply to CapsLock or NumLock
if ( !strnicmp("CAP",argv[2],3) ) {
KeyName = "CapsLock", KeyBit = CAPSLOCK_BIT
}
else if ( !strnicmp("NUM",argv[2],3) ) {
KeyName = "NumLock", KeyBit = NUMLOCK_BIT
} else {
KeyName = "Insert", KeyBit = INSERT_BIT
}
// perform action on the selected key
CurrentState = peek(KeysAddress)
switch( argv[1][0] ) {
case '+': // Set Key ON
poke(KeysAddress,CurrentState | KeyBit)
break
case '-': // Turn KEY OFF
poke(KeysAddress,CurrentState & ~KeyBit)
break
case '?': // display and return state of key
printf("%s is currently set %s.\n",KeyName,CurrentState & KeyBit ? "ON" : "OFF")
return( CurrentState & KeyBit ? 1 : 0 )
}
}
}


Instructions()
{
printf("\a\n")
printf("KeyState - Set, Clear, or Show the keyboard state of NumLock or CapsLock\n");
printf("\n");
printf("SYNTAX: KeyState < + | - | ? > < CAP | NUM | INS >\n");
printf("\n");
printf("Where: + Set KeyState ON\n");
printf(" - Set KeySTate OFF\n");
printf(" ? Display current Key State, and return ERRORLEVEL 1 if set\n");
printf(" and ERRORLEVEL 0 if clear\n");
printf(" NUM Apply command < + | - | ? > to the NumLock key\n");
printf(" CAP Apply command < + | - | ? > to the CapsLock key\n");
printf(" INS Apply command < + | - | ? > to the Insert key\n");
printf("\n");
printf("Examples: KeyState + Num Turn on the Numlock key\n");
printf(" KeyState - Cap Turn of the CapsLock key\n");
printf(" KeyState ? Num Show state of NumLock, return ERRORLEVEL if set\n");
printf("\n")
}

:SE_EXIT





ShawnAdministrator
(KiX Supporter)
2004-06-22 05:04 AM
Re: Case-Sensitive Sendkeys() or Keystate()

Curious stuff ...

ScriptEase

-Shawn


Kdyer
(KiX Supporter)
2004-06-22 07:43 AM
Re: Case-Sensitive Sendkeys() or Keystate()

Looks very similar to C..

But, Shawn may have nailed it.

Kent


AllenAdministrator
(KiX Supporter)
2004-06-22 04:54 PM
Re: Case-Sensitive Sendkeys() or Keystate()

Thanks guys... looks like a whole other scripting language ... first I've heard of ScriptEase. Oh well, I'll just hope Ruud might take this one on sometime.

Richard H.Administrator
(KiX Supporter)
2004-06-23 03:59 PM
Re: Case-Sensitive Sendkeys() or Keystate()

It looks like all "meta" keyboard keys will affect the result.

Run this script, and play with control, shift, caps lock and the "alt gr" keys (hit "q" to exit).

Code:
$=SetOption("WrapAtEOL","ON")
$=SetOption("CaseSensitivity","ON")

while Not($k="q" OR $k="Q")
while KBHIT()
Get $k
$k
loop
$=SendKeys("++x")
Loop
while KBHIT() Get $k Loop



As you cannot toggle things like the shift key a SendKeys() which can send the data unmodified is a better option.

A KeyState() while not solving the problem would be a useful addition too.


AllenAdministrator
(KiX Supporter)
2008-10-05 06:15 AM
Re: Case-Sensitive Sendkeys() or Keystate()

With the Dynawrapper dll, setting the keystate is now possible.

See SetKeyState - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=190022#Post190022