TheOnlyOne Posted November 11, 2010 Share Posted November 11, 2010 Hello i am creating a chat program. the problem is that i have binded enter to sending a msg so when i try to make a new line it just call that function i binded the new line to a other key. but still it did not work here is my code : hotkeyset("{enter}","_send") hotkeyset("+{enter}","newline") while 1 wend func _send() $edit1read = guictrlread($edit1) guictrlsetdata($edit1,"") sendchat(encrypt($edit1read,$cryptOffSet),$username,$channel) EndFunc func newline() $read = guictrlread($edit1) guictrlsetdata($edit1,$read & @crlf) EndFunc Okay there are 2 problems when i call the function new line it does not push the word down ( if the marker is in front of the word, when calling the function) the other problem is if i call the function 2 times at the top line (or any line) it jumps down to the buttom instead of only 1 level down pusing everything down. sorry for my bad english. btw this is only a part of my code. Link to comment Share on other sites More sharing options...
BugFix Posted November 11, 2010 Share Posted November 11, 2010 I don't like Hotkeys for this. You need, that this keys works only with your GUI. So it may be better to use Hook.You don't write something about your Edit-style. It's important. If you use default style, also included $ES_WANTRETURN. That means, that after hit ENTER automatically will inserted an @CRLF. In this case you don't need ...GuiCtrlSetData($Edit, GuiCtrlRead($Edit) & @CRLF).Here my solution:expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> Opt("GUIOnEventMode", 1) OnAutoItExitRegister('OnAutoItExit') Global $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam") Global $hmod = _WinAPI_GetModuleHandle(0) Global $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod) Global $gui, $edit, $active = False ; <== to allow hook only on this gui Global $isShift = False $gui = GUICreate('', 300, 170) GUISetOnEvent(-3, '_end') $edit = GUICtrlCreateEdit('', 10, 10, 280, 150) GUISetState() While 1 If BitAND(WinGetState($gui), 8) Then $active = True Else $active = False EndIf Sleep(100) WEnd Func _end() Exit EndFunc Func _send() ; for example only ConsoleWrite('_send(' & @CRLF & GUICtrlRead($edit) & @CRLF & ') was called' & @CRLF) EndFunc ;=========================================================== ; callback function ;=========================================================== Func _KeyProc($nCode, $wParam, $lParam) Local $tKEYHOOKS, $vkCode, $ID $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $nCode < 0 Or Not $active Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) $vkCode = DllStructGetData($tKEYHOOKS, "vkCode") If $wParam = $WM_KEYDOWN Then $ID = _WinAPI_GetDlgCtrlID(ControlGetHandle($gui, '', ControlGetFocus($gui))) ; get focus-ID from your gui If $ID <> $edit Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) ; Edit has not focus If $vkCode = 0xA0 Or $vkCode = 0xA1 Then ; left or right shift-button pressed $isShift = True EndIf If ( $vkCode = 13 ) And ( Not $isShift ) Then _send() Return -1 ; so the system get not the $vkCode 13 ElseIf ( $vkCode = 13 ) And $isShift Then GUICtrlSetData($ID, GUICtrlRead($ID)) ; if not using style $ES_WANTRETURN, use "GUICtrlRead($ID) & @CRLF" EndIf Else Switch DllStructGetData($tKEYHOOKS, "flags") Case 0x80, 0x81 ; 0x80= UP for 'normal' keys and left pairs, 0x81= UP for right pairs If $vkCode = 0xA0 Or $vkCode = 0xA1 Then $isShift = False ; LShift, RShift EndSwitch EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) EndFunc Best Regards BugFix 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