myspacee Posted March 23, 2009 Share Posted March 23, 2009 (edited) hello to all, extract from my script this : expandcollapse popup#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 March 23, 2009 by myspacee Link to comment Share on other sites More sharing options...
Authenticity Posted March 23, 2009 Share Posted March 23, 2009 Because q or Q has the same scan-code. If you want to determine if q is pressed rather than Q you'll need to check if the shift key is pressed as well as what is the state of the capslook toggle key. Link to comment Share on other sites More sharing options...
myspacee Posted March 23, 2009 Author Share Posted March 23, 2009 (edited) 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 March 23, 2009 by myspacee Link to comment Share on other sites More sharing options...
Authenticity Posted March 23, 2009 Share Posted March 23, 2009 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 More sharing options...
myspacee Posted March 23, 2009 Author Share Posted March 23, 2009 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 More sharing options...
Authenticity Posted March 23, 2009 Share Posted March 23, 2009 (edited) 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 March 23, 2009 by Authenticity Link to comment Share on other sites More sharing options...
Yashied Posted March 24, 2009 Share Posted March 24, 2009 Tryhttp://www.autoitscript.com/forum/index.php?showtopic=90492and http://www.autoitscript.com/forum/index.php?showtopic=90598 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
myspacee Posted March 24, 2009 Author Share Posted March 24, 2009 Thank you for replies,script portion posted come from my xpadder hook scriptPost also request to intercept hold down buttonI 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 More sharing options...
Authenticity Posted March 24, 2009 Share Posted March 24, 2009 (edited) 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. expandcollapse popupDim $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 March 24, 2009 by Authenticity Link to comment Share on other sites More sharing options...
myspacee Posted March 24, 2009 Author Share Posted March 24, 2009 thank you for reply and code testing now... ghetto solution, replace If _IsPressed("51", $dll) Then with If _IsPressed(_StringToHex(_StringProper($my_keyboard_shortcut_letter)), $dll) Then thank you again, m. Link to comment Share on other sites More sharing options...
Authenticity Posted March 24, 2009 Share Posted March 24, 2009 You always use the upper-case letter so you can store the capital in a variable and check the shift and capslock key state. The problem using this as an hot-key is that if 'Q' is posted in combination with shift then you'll need to hot-key shift+q as well. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now