Jump to content

q mistery


Recommended Posts

hello to all,

extract from my script this :

#include <String.au3>
#Include <Misc.au3>


dim $counter = 100
$my_keyboard_shortcut_letter = "q"

HotKeySet($my_keyboard_shortcut_letter,"_countdown")


msgbox(0,"","Hex code for " & $my_keyboard_shortcut_letter & "=" & _StringToHex($my_keyboard_shortcut_letter))


;;;; Body of program would go here;;;;
While 1
    Sleep(100)
WEnd




;---------------- FUNCTION
func _countdown()
    $dll = DllOpen("user32.dll")
    
    While 1
        $counter = $counter - 1
        If _IsPressed("51", $dll) Then
            tooltip("You are here for pressing 51 but " & @CRLF & @CRLF & "Holding " & $my_keyboard_shortcut_letter & "=" & _StringToHex($my_keyboard_shortcut_letter) & @CRLF & @CRLF & "                " & $counter & "/100")
            Sleep(1000)
            ToolTip("")     

        Else
            $counter = 100
            ExitLoop
        EndIf
        
        
        sleep(10)
    WEnd

    DllClose($dll)

EndFunc

run script, I map 'q' key as hotkey.

- First script returns 'q' and its hex code

- then hold 'q' to obtain countdown and some info about ascii-hex code

_____________________ Problem

ascii = hex

q = 71

Q = 51

I set 'q' as hotkey, but i must 'force' script to use 'Q' (51) to run :

If _IsPressed("51", $dll) Then

Why this ?

not all is clear for me, anyone can correct ?

thank you!

m.

Edited by myspacee
Link to comment
Share on other sites

Authenticity,

thank you for reply.

I don't want to determine if 'q' or 'Q' is pressed. I want only that my hotkey call my function. [understand holding key]

In this case :

- Hotkey is 'q'

- function is called correctly but

- I want to intercept when 'q' [hex:71] button is hold

- I must force 'Q' [hex:51] to allow script going on.

there is an error... but can't find.

m.

Edited by myspacee
Link to comment
Share on other sites

Something like this?

HotKeySet('q', 'MyFunc')
HotKeySet('{ESC}', '_EXIT')

Dim $hDll = DllOpen('user32.dll')
Dim $iCounter = 100

While 1
    Sleep(40)
WEnd

Func MyFunc()
    HotKeySet('q')
    
    While BitAND(0x8000, _GetAsyncKeyState(0x51)) ; Check if pressed and was pressed.
        While BitAND(0x0001, _GetAsyncKeyState(0x51))
            ToolTip('Release the key please.', @DesktopWidth-120, 0)
            Sleep(20)
        WEnd
    WEnd
    
    ToolTip('')
    HotKeySet('q', 'MyFunc')
EndFunc

Func _EXIT()
    DllClose($hDll)
    Exit
EndFunc


Func _GetAsyncKeyState($xKey)
    Local $aRet = DllCall($hDll, 'short', 'GetAsyncKeyState', 'int', $xKey)
    Return $aRet[0]
EndFunc

So your code is where the ToolTip function should get executed?

Link to comment
Share on other sites

very nice script.

but problem persist :

q = 71

Q = 51

you lock in script letter 'Q' but user press 'q'.

my problem is that i ask my users to insert 'function' key into .ini

So my user can define own personal hotkey

my users insert 'q' not 'Q'. How to manage this issue ?

[capitalize, then find hex code, for user defined hotkey?]

m.

Link to comment
Share on other sites

So you can get the key and upper-xase it. Anyway, I don't think the user should decide which key to use to call the hotkey function. What if the user insist to call it with ctrl+alt+del? or win_r? these are not allowed.

As for your case, you can use the upper-case of the letter always or if you think that Q rather than q should call the hot key function you should also check what is the state of the shift and the capslook keys. Shift + q + capslook toggled = 'q' right?

Edit: By the way, don't use _IsPress to determine if the capslook is toggled. You need to use GetKeyState (user32.dll) with the virtual-key value. MSDN - GetKeyState, the VK_* values are linked in the bottom of the page.

Edited by Authenticity
Link to comment
Share on other sites

Link to comment
Share on other sites

Thank you for replies,

script portion posted come from my xpadder hook script

Post also request to intercept hold down button

I need to implement it in my script (xpadder one) to allow user shutdown Pc from joypad holding down a key

(xpadder map any key to any joypad)

Script reserve a key to do several operation, but can't figure how bypass capitalization 'anomaly'

If only _IsPressed works with letters and not only with hex codes....

m.

Link to comment
Share on other sites

I hope it's not too cumbersome, you'll need to find or define ;] something to handle cases as strings as hotkey or eliminating erroneous hotkeys such as ctrl alone, etc.

Dim $sHotKey = 'Q' ; Lets say the user chose to use 'Q' instead of 'q'
Dim $AscKey = Asc($sHotKey)
Dim $hDll = DllOpen('user32.dll')
Dim $iCounter = 0
Dim $fUseUpper

HotKeySet('{ESC}', '_EXIT')

Select
    Case $AscKey <= 0x5A And $AscKey >= 0x41 ; Capitals
        $fUseUpper = True
        HotKeySet($sHotKey, 'MyFunc')
        HotKeySet(StringLower($sHotKey), 'MyFunc')
        HotKeySet('+' & $sHotKey, 'MyFunc')
        
    Case $AscKey <= 0x7A And $AscKey >= 0x61 ; The opposite of capitals ;]
        $fUseUpper = False
        HotKeySet($sHotKey, 'MyFunc')
        HotKeySet('+' & $sHotKey, 'MyFunc')
        
    Case Else
        HotKeySet($sHotKey, 'SomeKey') ; Won't work if the user want only ctrl to be the hot-key
EndSelect


While 1
    Sleep(40)
WEnd



Func MyFunc()
    HotKeySet('+' & $sHotKey)
    HotKeySet($sHotKey)
    Local $xKey = Asc(StringUpper($sHotKey))
    
    If $fUseUpper Then
        While _TranslateKey()
            If BitAND(_GetAsyncKeyState($xKey), 0x8000) Then
                ToolTip('Release the key please.', @DesktopWidth-140, 0)
                Sleep(100)
                $iCounter += 1
                If $iCounter >= 15 Then
                    ; Shutdown Windows and exit the script
                    Exit
                EndIf
            Else
                ExitLoop
            EndIf
        WEnd
    Else
        While Not _TranslateKey()
            If BitAND(_GetAsyncKeyState($xKey), 0x8000) Then
                ToolTip('Release the key please.', @DesktopWidth-140, 0)
                Sleep(100)
                $iCounter += 1
                If $iCounter >= 15 Then
                    ; Shutdown Windows and exit the script
                    Exit
                EndIf
            Else
                ExitLoop
            EndIf
        WEnd
    EndIf
    
   $iCounter = 0
    ToolTip('')
    HotKeySet($sHotKey, 'MyFunc')
    HotKeySet('+' & $sHotKey, 'MyFunc')
EndFunc

Func _EXIT()
    DllClose($hDll)
    Exit
EndFunc

Func SomeKey()
    ; Somekey
EndFunc

Func _TranslateKey()
    Return ((BitAND(_GetKeyState(0x14), 0x0001) > 0 And BitAND(_GetKeyState(0x10), 0x8000) = 0) Or _
              (BitAND(_GetKeyState(0x14), 0x0001) = 0 And BitAND(_GetKeyState(0x10), 0x8000) > 0))
EndFunc

Func _GetAsyncKeyState($xKey)
    Local $aRet = DllCall($hDll, 'short', 'GetAsyncKeyState', 'int', $xKey)
    Return $aRet[0]
EndFunc


Func _GetKeyState($xKey)
    Local $aRet = DllCall($hDll, 'short', 'GetKeyState', 'int', $xKey)
    Return $aRet[0]
EndFunc
Edited by Authenticity
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...