Okay, I got it now. Yes, it's the same with me as it is with you. I changed the template. Will be included in the next release. Thanks for that.
For now I post the complete code of Core.cs and of AgkFormTemplate.cs. So you can do the changes yourself for now.
Thanks again for the tip, also to Stan
AgkFormTemplate.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AgkSharp;
namespace TestInput
{
public partial class AgkFormTemplate : Form
{
bool init = false;
System.Windows.Forms.Timer agkSyncTimer = new System.Windows.Forms.Timer();
public AgkFormTemplate()
{
InitializeComponent();
}
private void ButtonUp_Click(object sender, EventArgs e)
{
Agk.SetSpritePosition(1, Agk.GetSpriteX(1), Agk.GetSpriteY(1) - 10);
}
private void ButtonDown_Click(object sender, EventArgs e)
{
Agk.SetSpritePosition(1, Agk.GetSpriteX(1), Agk.GetSpriteY(1) + 10);
}
private void ButtonLeft_Click(object sender, EventArgs e)
{
Agk.SetSpritePosition(1, Agk.GetSpriteX(1) - 10, Agk.GetSpriteY(1));
}
private void ButtonRight_Click(object sender, EventArgs e)
{
Agk.SetSpritePosition(1, Agk.GetSpriteX(1) + 10, Agk.GetSpriteY(1));
}
private void AgkFormTemplate_Shown(object sender, EventArgs e)
{
if (!init)
{
Agk.InitGL(AGKScreen.Handle);
AGKCore.Core.LoopInputs(AGKScreen);
init = true;
Agk.SetVirtualResolution(AGKScreen.Width, AGKScreen.Height);
//// display a background
//Agk.CreateSprite(Agk.LoadImage("media/background.jpg"));
//// create a sprite with ID that has no image
//Agk.CreateSprite(1, 0);
//Agk.SetSpritePosition(1, 130, 200);
//// add individual images into an animation list
//Agk.AddSpriteAnimationFrame(1, Agk.LoadImage("media/item0.png"));
//Agk.AddSpriteAnimationFrame(1, Agk.LoadImage("media/item1.png"));
//Agk.AddSpriteAnimationFrame(1, Agk.LoadImage("media/item2.png"));
//Agk.AddSpriteAnimationFrame(1, Agk.LoadImage("media/item3.png"));
//Agk.AddSpriteAnimationFrame(1, Agk.LoadImage("media/item4.png"));
//// play the sprite at 10 fps, looping, going from frame 1 to 5
//Agk.PlaySprite(1, 10, 1, 1, 5);
agkSyncTimer.Tick += new EventHandler(SyncTimer);
agkSyncTimer.Interval = 33; // ~ 30 fps
agkSyncTimer.Start();
}
}
private void SyncTimer(Object sender, EventArgs e)
{
AGKCore.Core.LoopAGK();
Agk.Print(string.Format("Mouse Pos: {0},{1}", Agk.GetRawMouseX(), Agk.GetRawMouseY()));
Agk.Print(string.Format("LButton: {0}", Agk.IsRawMouseLeftDown() ? "pressed" : "not pressed"));
Agk.Print(string.Format("LButton: {0}", Agk.IsRawMouseRightDown() ? "pressed" : "not pressed"));
Agk.Sync();
}
}
}
Core.cs
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using AgkSharp;
namespace AGKCore
{
public class Core
{
static Panel m_Window;
static bool m_bMaximized = false;
static bool m_bBreakLoop = false;
public static bool m_bDisableEscape = false;
[DllImport("user32.dll", SetLastError = true)]
static extern bool GetKeyboardState(byte[] lpKeyState);
[DllImport("user32.dll", SetLastError = true)]
static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetKeyboardLayout(uint idThread);
[DllImport("user32.dll", SetLastError = true)]
static extern int ToUnicodeEx(uint wVirtKey, uint wScanCode, byte[] lpKeyState, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwszBuff, int cchBuff, uint wFlags, IntPtr dwhkl);
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
static int TranslateKey(int key)
{
switch (key)
{
//case 20: key = 0; break; // Caps lock
//case 120: key = 0; break; // F9
//case 121: key = 0; break; // F10
//case 122: key = 0; break; // F11
//case 123: key = 0; break; // F12
//case 18: key = 18; break; // Alt Gr
//case 91: key = 0; break; // Windows key (left)
//case 92: key = 0; break; // Windows key (right)
// Num pad 0-9
case 96:
case 97:
case 98:
case 99:
case 100:
case 101:
case 102:
case 103:
case 104:
case 105: key -= 48; break;
case 111: key = 192; break; // Num pad /
case 109: key = 189; break; // Num pad -
case 110: key = 190; break; // Num pad .
//case 144: key = 0; break; // Num lock
//case 19: key = 0; break; // pause/break
}
return key;
}
static Char TranslateKeyToUnicode(Keys key)
{
Char result = new Char();
byte[] keyboardState = new byte[255];
bool keyboardStateStatus = GetKeyboardState(keyboardState);
if (!keyboardStateStatus)
{
return result;
}
uint virtualKeyCode = (uint)key;
uint scanCode = MapVirtualKey(virtualKeyCode, 0);
IntPtr inputLocaleIdentifier = GetKeyboardLayout(0);
StringBuilder txt = new StringBuilder();
ToUnicodeEx(virtualKeyCode, scanCode, keyboardState, txt, (int)5, (uint)0, inputLocaleIdentifier);
if (txt.Length > 0)
result = txt[0];
return result;
}
static void Core_OnClose(object sender, EventArgs e)
{
m_bBreakLoop = true;
}
static void Core_OnMouseMove(object sender, MouseEventArgs e)
{
Agk.MouseMove(0, e.X, e.Y);
}
static void Core_OnMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) Agk.MouseLeftButton(0, 1);
if (e.Button == MouseButtons.Right) Agk.MouseRightButton(0, 1);
if (e.Button == MouseButtons.Middle) Agk.MouseMiddleButton(0, 1);
}
static void Core_OnMouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) Agk.MouseLeftButton(0, 0);
if (e.Button == MouseButtons.Right) Agk.MouseRightButton(0, 0);
if (e.Button == MouseButtons.Middle) Agk.MouseMiddleButton(0, 0);
}
static void Core_OnMouseWheel(object sender, MouseEventArgs e)
{
Agk.MouseWheel(0, (float)e.Delta / 40);
}
static void Core_OnSizeChanged(object sender, EventArgs e)
{
//m_bMaximized = m_Window.WindowState == FormWindowState.Maximized;
m_bMaximized = false;
//m_Window.TopMost = m_bMaximized;
m_Window.Update();
Agk.UpdateDeviceSize();
Agk.WindowMoved();
}
static void Core_OnMove(object sender, EventArgs e)
{
Agk.WindowMoved();
}
static void Core_OnDeactivate(object sender, EventArgs e)
{
Agk.MouseLeftButton(0, 0);
Agk.MouseRightButton(0, 0);
Agk.MouseMiddleButton(0, 0);
//m_Window.TopMost = m_bMaximized;
m_Window.Update();
Agk.Paused();
Agk.WindowMoved();
}
static void Core_OnActivated(object sender, EventArgs e)
{
//m_Window.TopMost = m_bMaximized;
m_Window.Update();
Agk.Resumed();
Agk.WindowMoved();
}
static void Core_OnGotFocus(object sender, EventArgs e)
{
Agk.WindowMoved();
}
static void Core_OnLostFocus(object sender, EventArgs e)
{
Agk.WindowMoved();
}
public static void Core_OnKeyDown(object sender, KeyEventArgs e)
{
int key = TranslateKey(e.KeyValue);
if (key > 0)
Agk.KeyDown((uint)key);
if (!m_bDisableEscape && key == 27)
m_bBreakLoop = true;
Char chr = TranslateKeyToUnicode(e.KeyCode);
Agk.CharDown(chr);
}
static void Core_OnKeyUp(object sender, KeyEventArgs e)
{
int key = TranslateKey(e.KeyValue);
if (key > 0)
Agk.KeyUp((uint)key);
}
public static void LoopInputs(Panel form)
{
if (form != null)
{
m_Window = form;
form.MouseDown += Core_OnMouseDown;
form.MouseUp += Core_OnMouseUp;
form.MouseWheel += Core_OnMouseWheel;
form.MouseMove += Core_OnMouseMove;
form.SizeChanged += Core_OnSizeChanged;
form.Move += Core_OnMove;
//form.Activated += Core_OnActivated;
//form.Deactivate += Core_OnDeactivate;
form.GotFocus += Core_OnGotFocus;
form.LostFocus += Core_OnLostFocus;
form.KeyDown += Core_OnKeyDown;
form.KeyUp += Core_OnKeyUp;
//form.FormClosing += Core_OnClose;
}
}
public static bool LoopAGK()
{
Application.DoEvents();
if (Agk.IsCapturingImage() > 0)
System.Threading.Thread.Sleep(10);
return !m_bBreakLoop;
}
public static void CleanUp()
{
Agk.CleanUp();
}
}
}
Share your knowledge. It\'s a way to achieve immortality.
(Tenzin Gyatso)