Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline Davide Carpi  
#1 Posted : 07 February 2014 15:36:06(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
I was wondering if it was possible to have the OnKeyPress event handler in custom regions... f.e. would be useful to filter the inputs in the region placeholder (the onkeydown doesn't allow to detect all the characters, like the left parenthesis)
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline uni  
#2 Posted : 19 April 2014 16:11:54(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,494
Man
Russian Federation

Was thanked: 1274 time(s) in 745 post(s)
I join the request.
I'm trying to make an editor for scripts and I need more events:

OnKeyUp, OnKeyPress
OnClick, OnDoubleClick,
OnGotFocus, OnLostFocus

Now I have to somehow imitate them.
uni attached the following image(s):
2014-04-19 19-01-56 SMath Studio Desktop - [Лист1 ].png
Russia ☭ forever
Viacheslav N. Mezentsev
thanks 1 user thanked uni for this useful post.
on 19/04/2014(UTC)
Offline Davide Carpi  
#3 Posted : 19 April 2014 16:24:58(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Thank you Viacheslav, I'll add these requests in SS-72 OK


Best wishses and Happy Easter,

Davide


P.S.: do you know something about these (incomplete?) interfaces: IRegionWithEditableText, IRegionWithInputData ?
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 19/04/2014(UTC)
Offline uni  
#4 Posted : 19 April 2014 16:35:10(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,494
Man
Russian Federation

Was thanked: 1274 time(s) in 745 post(s)
Originally Posted by: w3b5urf3r_reloaded Go to Quoted Post
Thank you Viacheslav, I'll add these requests in SS-72 OK

Best wishses and Happy Easter,
Davide

P.S.: do you know something about these (incomplete?) interfaces: IRegionWithEditableText, IRegionWithInputData ?

Unfortunately, no. But I can tell how to simulate OnKeyPress().
Code:
    public class KeyCodeToAscii {

	    [DllImport("User32.dll")]
	    public static extern int ToAscii(int uVirtKey, int uScanCode, byte[] lpbKeyState, byte[] lpChar, int uFlags);

	    [DllImport("User32.dll")]
	    public static extern int GetKeyboardState(byte[] pbKeyState);

	    public static char GetAsciiCharacter(int uVirtKey) {

		    var lpKeyState = new byte[256];
		    
            GetKeyboardState( lpKeyState );
		    
            var lpChar = new byte[2];

		    if ( ToAscii( uVirtKey, 0, lpKeyState, lpChar, 0 ) == 1) {
			    
                return Convert.ToChar( ( lpChar[0] ) );

		    } else {
			    
                return new char();
		    }
	    }

    }


and

Code:
public override void OnKeyDown( KeyEventArgs e ) {
    
    var keyChar = KeyCodeToAscii.GetAsciiCharacter( e.KeyValue );

    OnKeyPress( new KeyPressEventArgs( keyChar ) );
}

public void OnKeyPress( KeyPressEventArgs e ) {

    // ...
}

But it works only with english characters.
uni attached the following image(s):
2014-04-19 19-27-00 SMath Studio Desktop - [Лист1 ].png
Russia ☭ forever
Viacheslav N. Mezentsev
thanks 1 user thanked uni for this useful post.
on 19/04/2014(UTC)
Offline Davide Carpi  
#5 Posted : 03 May 2014 03:33:18(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Originally Posted by: uni Go to Quoted Post
Unfortunately, no. But I can tell how to simulate OnKeyPress().

Really good hint... starting from here, I've deeply searched and in the end I've found this: http://stackoverflow.com/questions/370754/convert-a-keycode-to-the-relevant-display-character

Here a small adaptation:

Code:
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;

namespace ComboBoxListRegion
{
	/// <summary>
	/// hook adapted from: http://stackoverflow.com/questions/370754/convert-a-keycode-to-the-relevant-display-character
	/// </summary>
	public class KeyboardHelper
	{
		[DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
        private static extern int ToUnicodeEx(
            uint wVirtKey,
            uint wScanCode,
            Keys[] lpKeyState,
            StringBuilder pwszBuff,
            int cchBuff,
            uint wFlags,
            IntPtr dwhkl);

        [DllImport("user32.dll", ExactSpelling = true)]
        internal static extern IntPtr GetKeyboardLayout(uint threadId);

        [DllImport("user32.dll", ExactSpelling = true)]
        internal static extern bool GetKeyboardState(Keys[] keyStates);

        [DllImport("user32.dll", ExactSpelling = true)]
        internal static extern uint GetWindowThreadProcessId(IntPtr hwindow, out uint processId);

        public static string CodeToString(int scanCode)
        {
            uint procId;
            uint thread = GetWindowThreadProcessId(Process.GetCurrentProcess().MainWindowHandle, out procId);
            IntPtr hkl = GetKeyboardLayout(thread);

            if (hkl == IntPtr.Zero)
            {
                MessageBox.Show("Sorry, that keyboard does not seem to be valid.");
                return string.Empty;
            }

            Keys[] keyStates = new Keys[256];
            if (!GetKeyboardState(keyStates))
                return string.Empty;

            StringBuilder sb = new StringBuilder(10);
            int rc = ToUnicodeEx((uint)scanCode, (uint)scanCode, keyStates, sb, sb.Capacity, 0, hkl);
            return sb.ToString();
        }
	}
}


and

Code:
public override void OnKeyDown( KeyEventArgs e ) {
    
	string keyChar = KeyboardHelper.CodeToString( e.KeyValue );
	
	if (keyChar != String.Empty)
		OnKeyPress( new KeyPressEventArgs( (char)keyChar[0] ) );
}

public void OnKeyPress( KeyPressEventArgs e ) {

    // ...
}


This works also with Cyrillic and Greek Good

Edited by user 03 May 2014 12:08:39(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 03/05/2014(UTC)
Offline uni  
#6 Posted : 03 May 2014 12:14:08(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,494
Man
Russian Federation

Was thanked: 1274 time(s) in 745 post(s)
Andrey gave me to test the latest build. There OnKeyPress event is present. You can ask him for more events. Unfortunately, many of the events do not come to the component. For example, the arrow keys.
Russia ☭ forever
Viacheslav N. Mezentsev
thanks 1 user thanked uni for this useful post.
on 03/05/2014(UTC)
Offline Davide Carpi  
#7 Posted : 03 May 2014 12:21:08(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Originally Posted by: uni Go to Quoted Post
Andrey gave me to test the latest build. There OnKeyPress event is present. You can ask him for more events.

Many thanks Clap


Originally Posted by: uni Go to Quoted Post
Unfortunately, many of the events do not come to the component. For example, the arrow keys.

We have the OnKeyDown event, so we can handle the arrows from here (or I'm missing something? Huh )

Code:

public override void OnKeyDown(KeyEventArgs e)
{	
	if (!(this.ShowDescription && this.Description.Focused))
	{	
		if (e.KeyCode == Keys.Return)
		{
		  // ...
		}
		else if (e.KeyCode == Keys.Up)
		{
		  // ...
		}
		else if (e.KeyCode == Keys.Down)
		// ...
	}
	base.OnKeyDown(e);
}

Edited by user 03 May 2014 12:23:06(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline uni  
#8 Posted : 03 May 2014 12:31:00(UTC)
uni


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 10/11/2010(UTC)
Posts: 1,494
Man
Russian Federation

Was thanked: 1274 time(s) in 745 post(s)
Events from these keys do not reach the handler within the plugin because they used to work with the regions. Andrey, I hope, will correct this.
Russia ☭ forever
Viacheslav N. Mezentsev
thanks 1 user thanked uni for this useful post.
on 03/05/2014(UTC)
Offline Davide Carpi  
#9 Posted : 03 May 2014 12:41:19(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Originally Posted by: uni Go to Quoted Post
I hope, will correct this.

Thanks Viacheslav I've missed this point. I hope the same Good
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.