Sign in to follow this  
Followers 0
boogieoompa

Caps lock and shift

6 posts in this topic

I am having a slight problem, basically I have some code that I would only like to work in one program so that when someone goes to word or IE all of the keys that I am capturing (my code basically sets up hot keys) are relayed back to the key board. Right now it works fine until the user pushes caps lock at which time the user can nolonger push shift+button. Basically after they push caps lock the only way you can get a capital letter is by pressing caps lock. But shift works fine before the user press caps lock. Any suggestions?

Thanks

If $KeyStates[3] then
            HotKeySet("R")
            Send("R")
            HotKeySet("R", "FunRuler")      
        Else
            HotKeySet("r")
            Send("r")
            HotKeySet("r", "FunRuler")
        Endif
Func _GetKeyState() ;code snit bit provided by gafrost
    Const $VK_NUMLOCK = 0x90
    Const $VK_SCROLL = 0x91
    Const $VK_CAPITAL = 0x14
    Local $ret, $a_keystate[4]
    $a_keystate[0] = 3
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_NUMLOCK)
    $a_keystate[1] = $ret[0]
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_SCROLL)
    $a_keystate[2] = $ret[0]
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_CAPITAL)
    $a_keystate[3] = $ret[0]
    Return $a_keystate
EndFunc ;==>_GetKeyState

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try to be more specific.... You say that if the user presses CAPSLOCK then the script doesnt work right.If he turns off CAPSLOCK then the script works right or continues to be wrong?

If that is the case then make a hotkeyset with CAPSLOCK and put this in the function

Send("{CAPSLOCK OFF}")

Then you are goin to be sure that capslock is always turned off.

If that is the case,good.Otherwise be more specific please...

C ya

Edited by hgeras

Share this post


Link to post
Share on other sites

Sorry its a bit complicated. Basically if the user wants caps lock on it needs to stay on (we have some case sensitive apps :whistle: ) Here is specifically the problem.

When the user goes to another app with caps lock turned off the case is fine. The user can push shift and get a capital letter or get a lower case letter if he does not push shit. If the user then initiates caps lock the app starts to get a little wierd. With caps lock engaged the user can no longer make a lower case letter (even when holding down shift) and once the user turns caps lock off the user can no longer make captial letters using shift.

Share this post


Link to post
Share on other sites

I tested this as a standalone autoit app and it demonstrates the problem. If you run it and then go into notepad press caps lock and you will see what I am talking about. Incedentially I have noticed that the caps lock key flickers whenever I push a button during the wierd occurance.

Thanks

HotKeySet("r", "FunRuler")


While 1
    Sleep(100)
WEnd


Func FunRuler()
$KeyStates = _GetKeyState()
    If WinActive("Calculations") Then
        mouseclick("Right")
        Send("{Down},{Down},{Right},{Enter}")
        mouseclick("Left")
    Else
        If $KeyStates[3] then
            HotKeySet("R")
            Send("R")
            HotKeySet("R", "FunRuler")      
        Else
            HotKeySet("r")
            Send("r")
            HotKeySet("r", "FunRuler")
        Endif
    Endif

EndFunc
;---------------------------------------------------------------------------------------------

Func _GetKeyState()             ;Finds out if Caps is on
    Const $VK_NUMLOCK = 0x90
    Const $VK_SCROLL = 0x91
    Const $VK_CAPITAL = 0x14
    Local $ret, $a_keystate[4]
    $a_keystate[0] = 3
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_NUMLOCK)
    $a_keystate[1] = $ret[0]
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_SCROLL)
    $a_keystate[2] = $ret[0]
    $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_CAPITAL)
    $a_keystate[3] = $ret[0]
    Return $a_keystate
EndFunc ;==>_GetKeyState

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I changed the code of Getkeystate() and your code to do this.... This will do the trick.There is no bother if you press r or R or SHIFT+r or CAPSLOCK on or off or if you change windows or anything....

While 1

$KeyStates = _GetKeyState()
if $keystates=1 Then
    If WinActive("Calculations") Then
        mouseclick("Right")
        Send("{Down},{Down},{Right},{Enter}")
        mouseclick("Left")
    Endif
EndIf
WEnd
;---------------------------------------------------------------------------------------------

Func _GetKeyState()               
    Const $VK_R= 0x52
    Local $ret   
    $ret = DllCall("user32.dll", "int", "GetAsyncKeyState", "int", $VK_R)
    If $ret[0] <> 0 Then Return 1
EndFunc;==>_GetKeyState

Good luck.

EDIT:I corrected some code....

EDIT:After messing for an hour with MSDN and struggling for another one to make this work,I found out that there was a function IsPressed() that does the same thing.... :whistle::dance:

Edited by hgeras

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0