Get it on Google Play


Wm뮤 :: Wm뮤

블로그 이미지
가끔 그림그리거나 3D모델링하거나
취미로 로봇만드는
퇴직한 전자과 게임프로그래머
2020.3.48f1 , 2022.3.6f1 주로 사용
모카쨩
@Ahzkwid

Recent Comment

Archive


'전체 글'에 해당되는 글 1012건

  1. 2021.01.24 코드 모음 사이트
  2. 2021.01.20 스텐실
  3. 2021.01.18 수학 Math
  4. 2021.01.17 윈폼 키보드마우스
2021. 1. 24. 21:42 Unity/C#

www.delftstack.com/ko/howto/csharp/how-to-read-a-csv-file-and-store-its-values-into-an-array-in-csharp/

'Unity > C#' 카테고리의 다른 글

유니티 에디터 윈도우  (0) 2021.04.12
수학 Math  (0) 2021.01.18
화면관련  (0) 2021.01.17
posted by 모카쨩
2021. 1. 20. 09:17 Unity/shader

지우개

Shader "ahzkwid/Stencil/Invisible" {
    Properties {
        _MainTex ("MainTex", 2D) = "white" {}
        _Color ("Main Color", Color) = (1,1,1,1)
        _Stencil_Ref ("Stencil ID", int) = 3
        //_Cutoff("Cutout offset", Range(0, 1)) = 0.001
    }
    SubShader {
        Tags { 
        "RenderType"="Opaque" 
        "Queue"="Transparent"
        }
        
        //ColorMask RGB
        //Cull back
        //ZWrite off
        //ZTest Always
        Cull back
        ZWrite off
        //AlphaTest Greater [_Cutoff]
        //ZTest Always
        Stencil {
                //Ref 3
                Ref [_Stencil_Ref]
                Comp Always
                Pass Replace
        }
        Pass{
        	blend srcalpha oneminussrcalpha
            
	        SetTexture [_MainTex] 
	        {
	        	//Combine texture
	        	//Combine texture lerp(texture) constant
                //Combine texture* primary DOUBLE, texture* constant
                Combine texture* primary
	        }
	        SetTexture [_MainTex] 
	        {
	        	ConstantColor [_Color]
                Combine previous* constant
	        }
        }

    } 
}

 

 

지워질 대상

Shader "ahzkwid/Stencil/InvisibleTarget" {
    Properties {
        _MainTex ("MainTex", 2D) = "white" {}
        _Color ("Main Color", Color) = (1,1,1,1)
        _Stencil_Ref ("Stencil ID", int) = 3
        //_Stencil_Comp ("Stencil Comp", int) = 6
        //_Stencil_Pass ("Stencil OP", int) = 2
    }
    SubShader {
        Tags { 
        "RenderType"="Transparent" 
        "Queue"="Transparent"
        }

        //ColorMask RGB
        //Cull back
        //ZWrite off
        //ZTest Always
        Cull back
        ZWrite off
        //ZTest Always
        Stencil {
                //Ref 3
                Ref [_Stencil_Ref]
                Comp NotEqual
                Pass Replace
                //Comp [_Stencil_Comp]
                //Pass [_Stencil_Pass]
        }
        Pass{
        	blend srcalpha oneminussrcalpha
            
	        SetTexture [_MainTex] 
	        {
	        	//Combine texture
	        	//Combine texture lerp(texture) constant
                //Combine texture* primary DOUBLE, texture* constant
                Combine texture* primary
	        }
	        SetTexture [_MainTex] 
	        {
	        	ConstantColor [_Color]
                Combine previous* constant
	        }
        }

    } 
}

 

 

컷아웃 지우개

Shader "ahzkwid/Stencil/InvisibleCutout" {
    Properties {
        _MainTex ("MainTex", 2D) = "white" {}
        _Color ("Main Color", Color) = (1,1,1,1)
        _Stencil_Ref ("Stencil ID", int) = 3
        //_Cutoff("Cutout offset", Range(0, 1)) = 0.001
        //_Stencil_Comp ("Stencil Comp", int) = 0
        //_Stencil_Pass ("Stencil OP", int) = 2
    }
    SubShader {
        
Tags { "Queue" = "AlphaTest"
//"RenderType" = "TransparentCutout"
 "RenderType" = "Transparent" 
"IgnoreProjector" = "True" }
        //ColorMask RGB
        //Cull back
        //ZWrite off
        //ZTest Always
        Cull back
        ZWrite off
        //AlphaTest Greater [_Cutoff]
        AlphaTest Greater 0.001
        //ZTest Always
        Stencil {
                //Ref 3
                Ref [_Stencil_Ref]
                Comp Always
                Pass Replace
                //Comp [_Stencil_Comp]
                //Pass [_Stencil_Pass]
        }
        Pass{
        	blend srcalpha oneminussrcalpha

	        SetTexture [_MainTex] 
	        {
	        	//Combine texture
	        	//Combine texture lerp(texture) constant
                //Combine texture* primary DOUBLE, texture* constant
                Combine texture* primary
	        }
	        SetTexture [_MainTex] 
	        {
	        	ConstantColor [_Color]
                Combine previous* constant
	        }
        }

    } 
}

 

 

일반적으로는 컷아웃 지우개만 만들어서 아래걸 쓰면 된다

 

 

 

 

 

 

 

 

 

안쪽에 있는건 안보이게 하고 싶을때

 

원본

 

 

결과

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

마스크와 마스크 타겟

 

 

마스크

Always

Less

 

 

 

마스크 타겟

iD만 동일하면 된다

Equal

Keep

 

 

위 지우개로 마스크도 지울수 있다

아래는 예시 사진

빨강이 마스크고

파랑이 ID 4짜리 지우개

흰색이 마스크 타겟

 

 

 

Comp

0-Always

1-Never

2-Less

3-Equal

4-LEqual

5-Greater

6-NotEqual

7-GEqual

 

OP

0-Keep

1-Zero

2-Replace

3-IncrSat

4-DecrSat

5-Invert

6-IncrWrap

7-DecrWrap

posted by 모카쨩
2021. 1. 18. 16:35 Unity/C#

 

Xⁿ=Y 일때

n을 구하려면 log(Y) / log(X)                //로그
X를 구할려면 Sqrt(Y,n)                       //루트,제곱근, 여러개이면 거듭제곱근
Y를 구할려면 Pow(X,n) 혹은 Sqr(X,n)     //제곱,여러개이면 거듭제곱    

이상한 방법들

X를 구할때 보통을 sqrt를 써야하지만 인자를 1개만 받는 함수밖에 없을경우에
Pow(Y,1/n) //혹은 Sqr
이렇게 Pow를 써서 sqrt를 구할수도 있다
즉 Sqrt(x) = pow(x,1/2) 이다

 

Sqr계열

32의 5제곱근을 구할때

Sqr(32,1/5) //1은 고정숫자임

계산기 버전

 

 

 

 

log계열

 

//1024가 2의 몇승인지 구한다

Mathf.Log(1024,2)

다른버전

Mathf.Log(1024)/Mathf.Log(2)

계산기 버전

 

쓸모는 없지만

log(32)/5 = log(2)

이다

참고로 32는 2의 5제곱이다 즉

x^y=z일때

log(z)/y = log(x)

 

 

 

 

 

 

//npot를 최적의 2pot사이즈로 변경

wid=Mathf.Pow(2, Mathf.Round(Mathf.Log(texture.width, 2))));
hei=Mathf.Pow(2, Mathf.Round(Mathf.Log(texture.height, 2))));

/*
결과:
256->256
230->256
140->128
1031->1024
*/

 

 

 

 

원점에서의 거리

var len = sqrt(x*x + y*y);

 

 

x1,y1에서 x2,y2까지의 거리

 

 

 

 

 

 

 

Len과 dir을 이용하여 좌표를 구함

		public double d_set(double _Dir)
		{
			if(_Dir<0d)
			{
				_Dir=360d-((-_Dir)%360d);
			}
			if(_Dir>=360d)
			{
				return _Dir%360d;
			}
			return _Dir;
		}
		public double len_x(double _Len,double _Dir)
		{
			_Dir = d_set(_Dir);
			return _Len*Math.Cos(_Dir*Math.PI/180.0);
		}
        
		public double len_y(double _Len,double _Dir)
		{
			_Dir = d_set (_Dir);
			return _Len*Math.Sin(_Dir*Math.PI/180.0);
		}

 

 

pdir

x1,x2,y1,y2를 이용하여 각도를 구함

float2 center = 0.5;
float2 pos = i.uv.xy-center;
float2 dir  = ((atan2(pos.x,-pos.y)*2/3.14)/4+0.75)%1;

 

 

 

 

p1,p2,r,center를 이용하여 p3를 구하는 공식
챗GPT가 짜줬다

float2 FindIntersection(float2 p1, float2 p2, float R, float2 center)
{
    float2 dir = normalize(p2 - p1);
    float2 diff = p1 - center;

    // 원의 중심에서 선까지의 거리 d 계산
    float d = abs(diff.x * dir.y - diff.y * dir.x);

    // 만약 d가 R보다 크면 교점이 없음
    if (d >= R)
        return float2(0, 0);

    // L 계산: L = sqrt(R^2 - d^2)
    float L = sqrt(R * R - d * d);

    // 원의 중심에서 교점까지의 거리 h 계산: h = sqrt(R^2 - L^2)
    float h = sqrt(R * R - L * L);

    float2 midpoint = p1 + dot(center - p1, dir) * dir; // 선 위의 원의 중심에 수직인 점

    // 두 교점은 midpoint에서 ±L만큼 dir 방향으로 떨어져 있음
    float2 intersection1 = midpoint + L * dir;
    float2 intersection2 = midpoint - L * dir;

    // 이 예제에서는 두 교점 중 하나만 반환합니다.
    // 필요에 따라 두 교점 중 원하는 교점을 선택하여 반환하면 됩니다.
    return intersection1; 
}

 

'Unity > C#' 카테고리의 다른 글

코드 모음 사이트  (0) 2021.01.24
화면관련  (0) 2021.01.17
c# 기본 문법  (0) 2021.01.15
posted by 모카쨩
2021. 1. 17. 04:56 윈도우폼
    public static class mMouse
    {
        [DllImport("User32.dll")]
        public static extern int SetCursorPos(int x, int y);
        [DllImport("User32.dll")]
        public static extern int GetCursorPos(ref Point pos);

        [DllImport("user32.dll")] // 마우스 입력 
        static extern void mouse_event(uint dwFlags, uint dx, uint dy, int dwData, int dwExtraInfo);

        [System.Runtime.InteropServices.DllImport("User32.dll")] //마우스 상태
        public static extern int GetKeyboardState(ref byte[] pbKeyState);

        [DllImport("User32.dll")]
        public static extern short GetKeyState(int nVirtualKey);

        [DllImport("user32.dll")]
        static extern void keybd_event(byte vk, byte scan, int flags, int extrainfo);

        /*
        
            const byte AltKey = 18;
            const int KEYUP = 0x0002;    
            int Info=0;
            keybd_event(AltKey, 0, 0, ref Info);   // ALT key 다운
            keybd_event(AltKey, 0, KEYUP, ref Info);  // ALT key 업
        */
        //[System.Runtime.InteropServices.DllImport("user32.dll")] //마우스 상태
        //[return: MarshalAs(UnmanagedType.Bool)]
        //public static extern bool GetKeyboardState(byte[] pbKeyState);

        #region mouse_flag
        private const uint
            Absolute = 0x8000,
            LeftDown = 0x0002,
            LeftUp = 0x0004,
            MiddleDown = 0x0020,
            MiddleUp = 0x0040,
            Move = 0x0001,
            RightDown = 0x0008,
            RightUp = 0x0010,
            Wheel = 0x0800,
            XDown = 0x0080,
            XUp = 0x0100,
            HWheel = 0x1000;
        #endregion

        #region mouse_state
        private const byte
            LeftButton = 1,
            MiddleButton = 4,
            RightButton = 2;
        #endregion

        private static byte[] key_state = new byte[256];
        //public static mVec2 pos;

        public static int x
        {
            get
            {
                Point _pos = new Point();
                GetCursorPos(ref _pos);
                return _pos.X;
            }
            set
            {
                SetCursorPos(value, y);
            }
        }
        public static int y
        {
            get
            {
                Point _pos = new Point();
                GetCursorPos(ref _pos);
                return _pos.Y;
            }
            set
            {
                SetCursorPos(x, value);
            }
        }
        public static Point pos
        {
            get
            {
                Point _pos = new Point();
                GetCursorPos(ref _pos);
                return new Point(_pos.X, _pos.Y);
            }
            set
            {
                SetCursorPos((int)value.X, (int)value.Y);
            }
        }

        public static bool left
        {
            get
            {
                return (GetKeyState(LeftButton) & 0x80) != 0;
            }
            set
            {
                //uint _flag_t;
                if (value)
                {
                    //keybd_event(0x01, 0, 0,0);   // ALT key 다운
                    mouse_event(LeftDown, 0, 0, 0, 0);
                }
                else
                {
                    //keybd_event(0x01, 0, 0x0002, 0);   // ALT key 다운
                    mouse_event(LeftUp, 0, 0, 0, 0);
                }
            }
        }
    }

 

 

 


    public static class mKey
    {
        [DllImport("User32.dll")]
        public static extern short GetKeyState(int nVirtualKey);

        [System.Runtime.InteropServices.DllImport("user32.dll")] //키보드 상태
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern int GetKeyboardState(byte[] pbKeyState);

        [DllImport("user32.dll")]
        static extern void keybd_event(byte vk, byte scan, int flags, int extrainfo);

        private static bool hangleToggle = false;

        #region keyState
        private const int
            key_down = 0x0000,
            key_up = 0x0002;
        #endregion

        #region kr_key_index_array
        private static string[]
            krSyllableFirst =
            {
                "ㄱ","ㄲ","ㄴ","ㄷ","ㄸ","ㄹ","ㅁ","ㅂ","ㅃ","ㅅ",
                "ㅆ","ㅇ","ㅈ","ㅉ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"
            },
            krSyllableSecond =
            {
                "ㅏ","ㅐ","ㅑ","ㅒ","ㅓ","ㅔ","ㅕ","ㅖ","ㅗ","ㅗㅏ",
                "ㅗㅐ","ㅗㅣ","ㅛ","ㅜ","ㅜㅓ","ㅜㅔ","ㅜㅣ","ㅠ","ㅡ","ㅡㅣ",
                "ㅣ"
            },
            krSyllableThird =
            {
                "","ㄱ","ㄲ","ㄱㅅ","ㄴ","ㄴㅈ","ㄴㅎ","ㄷ","ㄹ","ㄹㄱ",
                "ㄹㅁ","ㄹㅂ","ㄹㅅ","ㄹㅌ","ㄹㅍ","ㄹㅎ","ㅁ","ㅂ","ㅂㅅ","ㅅ",
                "ㅆ","ㅇ","ㅈ","ㅊ","ㅋ","ㅌ","ㅍ","ㅎ"
            };
        #endregion


        #region VirtualKey
        public static byte


            vk_backspace = 0x08,
            vk_back = vk_backspace,  //BACKSPACE key

            vk_return = 0x0D,  //ENTER key
            vk_enter = vk_return,  //ENTER key

            vk_shift = 0x10,  //SHIFT key
            vk_control = 0x11,  //CTRL key
            vk_ctrl = vk_control,  //CTRL key


            vk_capital = 0x14,  //CAPS LOCK key
            vk_cap = vk_capital,  //CAPS LOCK key

            vk_hangul = 0x15, //hangul

            vk_escape = 0x1B,  //ESC key
            vk_esc = vk_escape,  //ESC key

            vk_space = 0x20,  //SPACEBAR


            vk_left = 0x25,  //LEFT ARROW key
            vk_le = vk_left,  //LEFT ARROW key
            vk_up = 0x26,  //UP ARROW key
            vk_right = 0x27,  //RIGHT ARROW key
            vk_ri = vk_right,  //RIGHT ARROW key
            vk_down = 0x28,  //DOWN ARROW key
            vk_do = vk_down,  //DOWN ARROW key




            vk_0 = 0x30,  //0 key
            vk_1 = 0x31,  //1 key
            vk_2 = 0x32,  //2 key
            vk_3 = 0x33,  //3 key
            vk_4 = 0x34,  //4 key
            vk_5 = 0x35,  //5 key
            vk_6 = 0x36,  //6 key
            vk_7 = 0x37,  //7 key
            vk_8 = 0x38,  //8 key
            vk_9 = 0x39,  //9 key
            vk_a = 0x41,  //A key
            vk_b = 0x42,  //B key
            vk_c = 0x43,  //C key
            vk_d = 0x44,  //D key
            vk_e = 0x45,  //E key
            vk_f = 0x46,  //F key
            vk_g = 0x47,  //G key
            vk_h = 0x48,  //H key
            vk_i = 0x49,  //I key
            vk_j = 0x4A,  //J key
            vk_k = 0x4B,  //K key
            vk_l = 0x4C,  //L key
            vk_m = 0x4D,  //M key
            vk_n = 0x4E,  //N key
            vk_o = 0x4F,  //O key
            vk_p = 0x50,  //P key
            vk_q = 0x51,  //Q key
            vk_r = 0x52,  //R key
            vk_s = 0x53,  //S key
            vk_t = 0x54,  //T key
            vk_u = 0x55,  //U key
            vk_v = 0x56,  //V key
            vk_w = 0x57,  //W key
            vk_x = 0x58,  //X key
            vk_y = 0x59,  //Y key
            vk_z = 0x5A,  //Z key




            vk_multiply = 0x6A,  // *
            vk_add = 0x6B,  // +
            vk_separator = 0x6C,  //Separator key
            vk_subtract = 0x6D,  // - 
            vk_decimal = 0x6E,  //.
            vk_divide = 0x6F,  // / key


            vk_oem_1 = 0xBA,  // ; :

            vk_oem_plus = 0xBB,  // = +
            vk_oem_comma = 0xBC,  // , <
            vk_oem_minus = 0xBD,  // - _
            vk_oem_period = 0xBE,  // . >

            vk_oem_2 = 0xBF,  // / ?
            vk_oem_3 = 0xC0,  // ` ~



            vk_oem_4 = 0xDB,  // [ {
            vk_oem_5 = 0xDC,  // \ |
            vk_oem_6 = 0xDD,  // ] }


            vk_oem_7 = 0xDE,  // ' "
            vk_oem_8 = 0xDf  //




        ;
        #endregion

        #region VirtualKey2
        public static int VK_LBUTTON = 0x01,  //Left mouse button
            VK_RBUTTON = 0x02,  //Right mouse button
            VK_CANCEL = 0x03,  //Control-break processing
            VK_MBUTTON = 0x04,  //Middle mouse button (three-button mouse)
            VK_BACK = 0x08,  //BACKSPACE key
            VK_TAB = 0x09,  //TAB key
            VK_CLEAR = 0x0C,  //CLEAR key
            VK_RETURN = 0x0D,  //ENTER key
            VK_SHIFT = 0x10,  //SHIFT key
            VK_CONTROL = 0x11,  //CTRL key
            VK_MENU = 0x12,  //ALT key
            VK_PAUSE = 0x13,  //PAUSE key
            VK_CAPITAL = 0x14,  //CAPS LOCK key
            VK_HANGUL = 0x15,
            VK_ESCAPE = 0x1B,  //ESC key
            VK_SPACE = 0x20,  //SPACEBAR
            VK_PRIOR = 0x21,  //PAGE UP key
            VK_NEXT = 0x22,  //PAGE DOWN key
            VK_END = 0x23,  //END key
            VK_HOME = 0x24,  //HOME key
            VK_LEFT = 0x25,  //LEFT ARROW key
            VK_UP = 0x26,  //UP ARROW key
            VK_RIGHT = 0x27,  //RIGHT ARROW key
            VK_DOWN = 0x28,  //DOWN ARROW key
            VK_SELECT = 0x29,  //SELECT key
            VK_PRINT = 0x2A,  //PRINT key
            VK_EXECUTE = 0x2B,  //EXECUTE key
            VK_SNAPSHOT = 0x2C,  //PRINT SCREEN key
            VK_INSERT = 0x2D,  //INS key
            VK_DELETE = 0x2E,  //DEL key
            VK_HELP = 0x2F,  //HELP key
            VK_0 = 0x30,  //0 key
            VK_1 = 0x31,  //1 key
            VK_2 = 0x32,  //2 key
            VK_3 = 0x33,  //3 key
            VK_4 = 0x34,  //4 key
            VK_5 = 0x35,  //5 key
            VK_6 = 0x36,  //6 key
            VK_7 = 0x37,  //7 key
            VK_8 = 0x38,  //8 key
            VK_9 = 0x39,  //9 key
            VK_A = 0x41,  //A key
            VK_B = 0x42,  //B key
            VK_C = 0x43,  //C key
            VK_D = 0x44,  //D key
            VK_E = 0x45,  //E key
            VK_F = 0x46,  //F key
            VK_G = 0x47,  //G key
            VK_H = 0x48,  //H key
            VK_I = 0x49,  //I key
            VK_J = 0x4A,  //J key
            VK_K = 0x4B,  //K key
            VK_L = 0x4C,  //L key
            VK_M = 0x4D,  //M key
            VK_N = 0x4E,  //N key
            VK_O = 0x4F,  //O key
            VK_P = 0x50,  //P key
            VK_Q = 0x51,  //Q key
            VK_R = 0x52,  //R key
            VK_S = 0x53,  //S key
            VK_T = 0x54,  //T key
            VK_U = 0x55,  //U key
            VK_V = 0x56,  //V key
            VK_W = 0x57,  //W key
            VK_X = 0x58,  //X key
            VK_Y = 0x59,  //Y key
            VK_Z = 0x5A,  //Z key
            VK_NUMPAD0 = 0x60,  //Numeric keypad 0 key
            VK_NUMPAD1 = 0x61,  //Numeric keypad 1 key
            VK_NUMPAD2 = 0x62,  //Numeric keypad 2 key
            VK_NUMPAD3 = 0x63,  //Numeric keypad 3 key
            VK_NUMPAD4 = 0x64,  //Numeric keypad 4 key
            VK_NUMPAD5 = 0x65,  //Numeric keypad 5 key
            VK_NUMPAD6 = 0x66,  //Numeric keypad 6 key
            VK_NUMPAD7 = 0x67,  //Numeric keypad 7 key
            VK_NUMPAD8 = 0x68,  //Numeric keypad 8 key
            VK_NUMPAD9 = 0x69,  //Numeric keypad 9 key
            VK_SEPARATOR = 0x6C,  //Separator key
            VK_SUBTRACT = 0x6D,  //Subtract key
            VK_DECIMAL = 0x6E,  //Decimal key
            VK_DIVIDE = 0x6F,  //Divide key
            VK_F1 = 0x70,  //F1 key
            VK_F2 = 0x71,  //F2 key
            VK_F3 = 0x72,  //F3 key
            VK_F4 = 0x73,  //F4 key
            VK_F5 = 0x74,  //F5 key
            VK_F6 = 0x75,  //F6 key
            VK_F7 = 0x76,  //F7 key
            VK_F8 = 0x77,  //F8 key
            VK_F9 = 0x78,  //F9 key
            VK_F10 = 0x79,  //F10 key
            VK_F11 = 0x7A,  //F11 key
            VK_F12 = 0x7B,  //F12 key
            VK_SCROLL = 0x91,  //SCROLL LOCK key
            VK_LSHIFT = 0xA0,  //Left SHIFT key
            VK_RSHIFT = 0xA1,  //Right SHIFT key
            VK_LCONTROL = 0xA2,  //Left CONTROL key
            VK_RCONTROL = 0xA3,  //Right CONTROL key
            VK_LMENU = 0xA4,   //Left MENU key
            VK_RMENU = 0xA5,  //Right MENU key
            VK_PLAY = 0xFA,  //Play key
            VK_ZOOM = 0xFB //Zoom key
            ;
        #endregion

        private static byte[] keyState = new byte[256];

        public static bool enter
        {
            get
            {
                return KeyboardCheck(vk_enter);
            }
            set
            {
                if (value)
                {
                    keybd_event(vk_enter, 0, key_down, 0);
                }
                else
                {
                    keybd_event(vk_enter, 0, key_up, 0);
                }
            }
        }
        public static bool esc
        {
            get
            {
                return KeyboardCheck(vk_esc);
            }
            set
            {
                if (value)
                {
                    keybd_event(vk_esc, 0, key_down, 0);
                }
                else
                {
                    keybd_event(vk_esc, 0, key_up, 0);
                }
            }
        }
        public static bool shift
        {
            get
            {
                return KeyboardCheck(vk_shift);
            }
            set
            {
                if (value)
                {
                    keybd_event(vk_shift, 0, key_down, 0);
                }
                else
                {
                    keybd_event(vk_shift, 0, key_up, 0);
                }
            }
        }
        public static bool space
        {
            get
            {
                return KeyboardCheck(vk_space);
            }
            set
            {
                if (value)
                {
                    keybd_event(vk_space, 0, key_down, 0);
                }
                else
                {
                    keybd_event(vk_space, 0, key_up, 0);
                }
            }
        }
        public static bool back
        {
            get
            {
                return KeyboardCheck(vk_back);
            }
            set
            {
                if (value)
                {
                    keybd_event(vk_back, 0, key_down, 0);
                }
                else
                {
                    keybd_event(vk_back, 0, key_up, 0);
                }
            }
        }
        public static bool ctrl
        {
            get
            {
                return KeyboardCheck(vk_ctrl);
            }
            set
            {
                if (value)
                {
                    keybd_event(vk_ctrl, 0, key_down, 0);
                }
                else
                {
                    keybd_event(vk_ctrl, 0, key_up, 0);
                }
            }
        }
        public static bool hangul
        {
            get
            {
                return hangleToggle;
            }
            set
            {
                if (value != hangul)
                {
                    keybd_event(vk_hangul, 0, key_down, 0);
                    keybd_event(vk_hangul, 0, key_up, 0);
                    hangleToggle = value;
                }
            }
        }
        public static bool cap
        {
            get
            {
                return KeyboardCheckToggle(vk_cap);
            }
            set
            {
                if (value != cap)
                {
                    keybd_event(vk_cap, 0, key_down, 0);
                    keybd_event(vk_cap, 0, key_up, 0);
                }
            }
        }
        public static bool KeyCheck(int key)
        {
            return KeyboardCheck(key);
        }
        public static bool KeyCheckToggle(int key)
        {
            return KeyboardCheckToggle(key);
        }
        public static bool KeyboardCheckToggle(int key)
        {
            return (GetKeyState(key) & 0x0001) != 0;
            // GetKeyboardState(keyState);
        }
        public static bool KeyboardCheck(int key)
        {
            return (GetKeyState(key) & 0x8000) > 0;
            // GetKeyboardState(keyState);
        }
        public static void KeyPress(string text)
        {

            byte[] keycodes = ConvertKeycode(text);
            bool[] checkShiftCharacters = CheckShiftCharacter(text);
            bool[] bo_hangul = ConvertToSimpleAndIfKr(text);



            for (int i = 0; i < keycodes.Length; i++)
            {

                shift = checkShiftCharacters[i];
                if (hangul != bo_hangul[i])
                {
                    hangul = bo_hangul[i];
                    Thread.Sleep(200);
                }
                keybd_event(keycodes[i], 0, key_down, 0);
                keybd_event(keycodes[i], 0, key_up, 0);
            }
            shift = false;
            if (hangul != false)
            {
                space = true;
                space = false;

                back = true;
                back = false;

                hangul = false;
                Thread.Sleep(200);
            }
        }


        public static bool KrExists(string text)
        {
            return Array.Find(CheckKrCharacter(text), x => x == true);
        }
        public static bool[] ConvertToSimpleAndIfKr(string text)
        {
            return CheckKrCharacter(ConvertKrKey(text));
        }
        public static bool[] CheckKrCharacter(string text)
        {
            return System.Array.ConvertAll(text.ToCharArray(), x => CheckKrCharacter(x));
        }
        public static bool CheckKrCharacter(char character)
        {
            return ((character >= 0x1100) && (character <= 0x11FF))
                || ((character >= 0x3131) && (character <= 0x319E))
                || ((character >= 0xAC00) && (character <= 0xD7A3));
        }

        public static bool CheckCompletionKr(char character)
        {
            return (character >= 0xAC00) && (character <= 0xD7A3);
        }

        public static byte[] ConvertKeycode(string text)
        {
            return System.Array.ConvertAll(ConvertKrKey(text).ToCharArray(), x => ConvertKeycode(x)); 
        }
        public static byte ConvertKeycode(char character)
        {
            switch (character)
            {

                case '\n':
                    return vk_enter;

                case ';':
                case ':':
                    return vk_oem_1;
                case '/':
                case '?':
                    return vk_oem_2;
                case '`':
                case '~':
                    return vk_oem_3;
                case '[':
                case '{':
                    return vk_oem_4;
                case '\\':
                case '|':
                    return vk_oem_5;
                case ']':
                case '}':
                    return vk_oem_6;
                case '\'':
                case '"':
                    return vk_oem_7;
                case '=':
                case '+':
                    return vk_oem_plus;
                case '-':
                case '_':
                    return vk_oem_minus;
                case ',':
                case '<':
                    return vk_oem_comma;
                case '.':
                case '>':
                    return vk_oem_period;

                case ' ':
                    return vk_space;
                case '0':
                case ')':
                    return vk_0;
                case '1':
                case '!':
                    return vk_1;
                case '2':
                case '@':
                    return vk_2;
                case '3':
                case '#':
                    return vk_3;
                case '4':
                case '$':
                    return vk_4;
                case '5':
                case '%':
                    return vk_5;
                case '6':
                case '^':
                    return vk_6;
                case '7':
                case '&':
                    return vk_7;
                case '8':
                case '*':
                    return vk_8;
                case '9':
                case '(':
                    return vk_9;
                case 'a':
                case 'A':
                case 'ㅁ':
                    return vk_a;
                case 'b':
                case 'B':
                case 'ㅠ':
                    return vk_b;
                case 'c':
                case 'C':
                case 'ㅊ':
                    return vk_c;
                case 'd':
                case 'D':
                case 'ㅇ':
                    return vk_d;
                case 'e':
                case 'E':
                case 'ㄷ':
                case 'ㄸ':
                    return vk_e;
                case 'f':
                case 'F':
                case 'ㄹ':
                    return vk_f;
                case 'g':
                case 'G':
                case 'ㅎ':
                    return vk_g;
                case 'h':
                case 'H':
                case 'ㅗ':
                    return vk_h;
                case 'i':
                case 'I':
                case 'ㅑ':
                    return vk_i;
                case 'j':
                case 'J':
                case 'ㅓ':
                    return vk_j;
                case 'k':
                case 'K':
                case 'ㅏ':
                    return vk_k;
                case 'l':
                case 'L':
                case 'ㅣ':
                    return vk_l;
                case 'm':
                case 'M':
                case 'ㅡ':
                    return vk_m;
                case 'n':
                case 'N':
                case 'ㅜ':
                    return vk_n;
                case 'o':
                case 'O':
                case 'ㅐ':
                case 'ㅒ':
                    return vk_o;
                case 'p':
                case 'P':
                case 'ㅔ':
                case 'ㅖ':
                    return vk_p;
                case 'q':
                case 'Q':
                case 'ㅂ':
                case 'ㅃ':
                    return vk_q;
                case 'r':
                case 'R':
                case 'ㄱ':
                case 'ㄲ':
                    return vk_r;
                case 's':
                case 'S':
                case 'ㄴ':
                    return vk_s;
                case 't':
                case 'T':
                case 'ㅅ':
                case 'ㅆ':
                    return vk_t;
                case 'u':
                case 'U':
                case 'ㅕ':
                    return vk_u;
                case 'v':
                case 'V':
                case 'ㅍ':
                    return vk_v;
                case 'w':
                case 'W':
                case 'ㅈ':
                case 'ㅉ':
                    return vk_w;
                case 'x':
                case 'X':
                case 'ㅌ':
                    return vk_x;
                case 'y':
                case 'Y':
                case 'ㅛ':
                    return vk_y;
                case 'z':
                case 'Z':
                case 'ㅋ':
                    return vk_z;
            }
            return 0;
        }

        public static bool[] CheckShiftCharacter(string text)
        {
            return System.Array.ConvertAll(ConvertKrKey(text).ToCharArray(), x => CheckShiftCharacter(x));
        }
        public static bool CheckShiftCharacter(char character)
        {
            switch (character)
            {



                case '<':
                case '>':
                case '?':
                case '"':
                case ':':
                case '{':
                case '}':
                case '_':
                case '+':
                case '|':
                case '~':

                case ')':
                case '!':
                case '@':
                case '#':
                case '$':
                case '%':
                case '&':
                case '*':
                case '^':
                case '(':

                case 'A':
                case 'B':
                case 'C':
                case 'D':
                case 'E':
                case 'ㄸ':
                case 'F':
                case 'G':
                case 'H':
                case 'I':
                case 'J':
                case 'K':
                case 'L':
                case 'M':
                case 'N':
                case 'O':
                case 'ㅒ':
                case 'P':
                case 'ㅖ':
                case 'Q':
                case 'ㅃ':
                case 'R':
                case 'ㄲ':
                case 'S':
                case 'T':
                case 'ㅆ':
                case 'U':
                case 'V':
                case 'W':
                case 'ㅉ':
                case 'X':
                case 'Y':
                case 'Z':
                    return true;
            }
            return false;
        }

        public static string ConvertKrKey(string text)
        {
            return string.Concat(System.Array.ConvertAll(text.ToCharArray(), x => ConvertKrKey(x)));
        }
        public static string ConvertKrKey(char character)
        {
            string text = "";
            if (!CheckCompletionKr(character))
            {
                text += character;
                return text;
            }
            int char_number = character - 0xAC00;
            text += krSyllableFirst[char_number / (28 * 21)];
            text += krSyllableSecond[(char_number % (28 * 21)) / 28];
            text += krSyllableThird[char_number % 28];
            return text;
        }

    }

'윈도우폼' 카테고리의 다른 글

DLL 생성 예제  (0) 2021.02.11
c# 멀티스레드 기본소스  (0) 2020.11.23
자주 쓰는 윈폼 코드 모음  (0) 2020.10.31
posted by 모카쨩

  • total
  • today
  • yesterday

Recent Post

저사양 유저용 블로그 진입