Guten Tag,
ich versuche zurzeit in C# einen Keybinder für SAMP zu schreiben.
Nun brauche ich eure Hilfe!
Wie schaffe ich es das die Binds von der Windows Form erkannt werden ?
Kann mir da jemand mal ein Beispiel Script geben ?`
LG, Julian_Alvarez
Guten Tag,
ich versuche zurzeit in C# einen Keybinder für SAMP zu schreiben.
Nun brauche ich eure Hilfe!
Wie schaffe ich es das die Binds von der Windows Form erkannt werden ?
Kann mir da jemand mal ein Beispiel Script geben ?`
LG, Julian_Alvarez
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace SampKeyHook
{
    internal class KeyMonitor
    {
        private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
        private const int WH_KEYBOARD_LL = 13;
        private const int WM_KEYDOWN = 0x0100;
        private static KeyMonitor.LowLevelKeyboardProc _proc = new KeyMonitor.LowLevelKeyboardProc(KeyMonitor.HookCallback);
        private static IntPtr _hookID = IntPtr.Zero;
        public static IntPtr Start()
        {
            KeyMonitor._hookID = KeyMonitor.SetHook(KeyMonitor._proc);
            Debug.WriteLine("KeyHook gestartet, ID: " + KeyMonitor._hookID);
            return KeyMonitor._hookID;
        }
        private static IntPtr SetHook(KeyMonitor.LowLevelKeyboardProc proc)
        {
            IntPtr result;
            using (Process currentProcess = Process.GetCurrentProcess())
            {
                using (ProcessModule curModule = currentProcess.MainModule)
                {
                    result = KeyMonitor.SetWindowsHookEx(WH_KEYBOARD_LL, proc, KeyMonitor.GetModuleHandle(curModule.ModuleName), 0u);
                }
            }
            return result;
        }
        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
            {
                int num = Marshal.ReadInt32(lParam);
                string text = ((Keys)num).ToString();
                if (text.Equals("F9"))
                {
                    SLaYz.API.SampAPI.SampAddChat(54145, "Das ist ein Test.");
                }
                if(text.Equals("D1"))
                {
                    SLaYz.API.SampAPI.SampAddChat(54145, "==================================================================");
                    SLaYz.API.SampAPI.SampAddChat(54145, "Diese Nachricht wurde vom System erstellt und ist nicht Legitim.");
                    SLaYz.API.SampAPI.SampAddChat(54145, "==================================================================");
                }
                Debug.WriteLine("Keyboard Event: " + text.ToString());
            }
            return KeyMonitor.CallNextHookEx(KeyMonitor._hookID, nCode, wParam, lParam);
        }
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr SetWindowsHookEx(int idHook, KeyMonitor.LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool UnhookWindowsHookEx(IntPtr hhk);
        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern IntPtr GetModuleHandle(string lpModuleName);
    }
}
	
			Alles anzeigen
	Damit sollte es Klappen (Vorrausgesetzt du hast die API)
Die API habe ich nicht :o könntest du mir die vlt. schicken ?