|
-
Jul 8th, 2012, 05:13 PM
#1
Shift key using GetAsyncKeyState
I know how to detect when the Shift key has been pressed so I turn on an indicator then I can put upper case characters in the text box but I have no idea how to know/detect when the user has released the shift key.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 10th, 2012, 11:20 AM
#2
Junior Member
Re: Shift key using GetAsyncKeyState
In autoitscript I used the following method:
Code:
do
;nothing
until ( the shift button is pressed)
I'm not sure if it could apply, but you could try checking if the getasynckeystate <> shift key.
-
Jul 10th, 2012, 01:18 PM
#3
Re: Shift key using GetAsyncKeyState
Checking if <> shift key will occur since the next key coming in will be a character like a, b, c, etc.
The problem is I can detect when the shift key was pressed and that allows me to make the characters upper case but I have not found a way to detect if the shift key has been released so I can make the characters lower case again.
When the shift key is pressed I set an indicator to tell my code to make all characters upper case until the shift key has been released. Since I have not been able to detect this and not reset the indicator the characters keep printing in upper case even though they shift key has long been released.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 13th, 2012, 01:30 PM
#4
New Member
Re: Shift key using GetAsyncKeyState
Put this code to module
Code:
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
put this in a timer , make the interval 100
these are the codes for the key codes
Code:
Private Const VK_0 = &H30
Private Const VK_1 = &H31
Private Const VK_2 = &H32
Private Const VK_3 = &H33
Private Const VK_4 = &H34
Private Const VK_5 = &H35
Private Const VK_6 = &H36
Private Const VK_7 = &H37
Private Const VK_8 = &H38
Private Const VK_9 = &H39
Private Const VK_A = &H41
Private Const VK_B = &H42
Private Const VK_C = &H43
Private Const VK_D = &H44
Private Const VK_E = &H45
Private Const VK_F = &H46
Private Const VK_G = &H47
Private Const VK_H = &H48
Private Const VK_I = &H49
Private Const VK_J = &H4A
Private Const VK_K = &H4B
Private Const VK_L = &H4C
Private Const VK_M = &H4D
Private Const VK_N = &H4E
Private Const VK_O = &H4F
Private Const VK_P = &H50
Private Const VK_Q = &H51
Private Const VK_R = &H52
Private Const VK_S = &H53
Private Const VK_T = &H54
Private Const VK_U = &H55
Private Const VK_V = &H56
Private Const VK_W = &H57
Private Const VK_X = &H58
Private Const VK_Y = &H59
Private Const VK_Z = &H5A
Private Const VK_ADD = &H6B
Private Const VK_ATTN = &HF6
Private Const VK_BACK = &H8
Private Const VK_CANCEL = &H3
Private Const VK_CAPITAL = &H14
Private Const VK_CLEAR = &HC
Private Const VK_CONTROL = &H11
Private Const VK_CRSEL = &HF7
Private Const VK_DECIMAL = &H6E
Private Const VK_DELETE = &H2E
Private Const VK_DIVIDE = &H6F
Private Const VK_DOWN = &H28
Private Const VK_END = &H23
Private Const VK_EREOF = &HF9
Private Const VK_ESCAPE = &H1B
Private Const VK_EXECUTE = &H2B
Private Const VK_EXSEL = &HF8
Private Const VK_F1 = &H70
Private Const VK_F10 = &H79
Private Const VK_F11 = &H7A
Private Const VK_F12 = &H7B
Private Const VK_F13 = &H7C
Private Const VK_F14 = &H7D
Private Const VK_F15 = &H7E
Private Const VK_F16 = &H7F
Private Const VK_F17 = &H80
Private Const VK_F18 = &H81
Private Const VK_F19 = &H82
Private Const VK_F2 = &H71
Private Const VK_F20 = &H83
Private Const VK_F21 = &H84
Private Const VK_F22 = &H85
Private Const VK_F23 = &H86
Private Const VK_F24 = &H87
Private Const VK_F3 = &H72
Private Const VK_F4 = &H73
Private Const VK_F5 = &H74
Private Const VK_F6 = &H75
Private Const VK_F7 = &H76
Private Const VK_F8 = &H77
Private Const VK_F9 = &H78
Private Const VK_HELP = &H2F
Private Const VK_HOME = &H24
Private Const VK_INSERT = &H2D
Private Const VK_LBUTTON = &H1
Private Const VK_LCONTROL = &HA2
Private Const VK_LEFT = &H25
Private Const VK_LMENU = &HA4
Private Const VK_LSHIFT = &HA0
Private Const VK_MBUTTON = &H4
Private Const VK_MENU = &H12
Private Const VK_MULTIPLY = &H6A
Private Const VK_NEXT = &H22
Private Const VK_NONAME = &HFC
Private Const VK_NUMLOCK = &H90
Private Const VK_NUMPAD0 = &H60
Private Const VK_NUMPAD1 = &H61
Private Const VK_NUMPAD2 = &H62
Private Const VK_NUMPAD3 = &H63
Private Const VK_NUMPAD4 = &H64
Private Const VK_NUMPAD5 = &H65
Private Const VK_NUMPAD6 = &H66
Private Const VK_NUMPAD7 = &H67
Private Const VK_NUMPAD8 = &H68
Private Const VK_NUMPAD9 = &H69
Private Const VK_OEM_CLEAR = &HFE
Private Const VK_PA1 = &HFD
Private Const VK_PAUSE = &H13
Private Const VK_PLAY = &HFA
Private Const VK_PRINT = &H2A
Private Const VK_PRIOR = &H21
Private Const VK_PROCESSKEY = &HE5
Private Const VK_RBUTTON = &H2
Private Const VK_RCONTROL = &HA3
Private Const VK_RETURN = &HD
Private Const VK_RIGHT = &H27
Private Const VK_RMENU = &HA5
Private Const VK_RSHIFT = &HA1
Private Const VK_SCROLL = &H91
Private Const VK_SELECT = &H29
Private Const VK_SEPARATOR = &H6C
Private Const VK_SHIFT = &H10
Private Const VK_SNAPSHOT = &H2C
Private Const VK_SPACE = &H20
Private Const VK_SUBTRACT = &H6D
Private Const VK_TAB = &H9
Private Const VK_UP = &H26
Private Const VK_ZOOM = &HFB
Code:
If GetAsyncKeyState(VK_LSHIFT) Then ' if shift pressed do bla bla bla
'
'
End If
End If
goodbye,
-
Jul 13th, 2012, 02:17 PM
#5
Re: Shift key using GetAsyncKeyState
 Originally Posted by rac1
Put this code to module
Code:
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
put this in a timer , make the interval 100
these are the codes for the key codes
Code:
Private Const VK_0 = &H30
Private Const VK_1 = &H31
Private Const VK_2 = &H32
'
'
'
Private Const VK_SUBTRACT = &H6D
Private Const VK_TAB = &H9
Private Const VK_UP = &H26
Private Const VK_ZOOM = &HFB
Code:
If GetAsyncKeyState(VK_LSHIFT) Then ' if shift pressed do bla bla bla
'
'
End If
End If
goodbye,
That doesn't solve the problem that is the problem.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 13th, 2012, 06:43 PM
#6
New Member
Re: Shift key using GetAsyncKeyState
If you subclass the edit control you'll get WM_Keydown/WM_Keyup messages. I confirmed with Spy++ that Notepad's edit control does recieve these messages for Shift.
-
Jul 13th, 2012, 08:01 PM
#7
Re: Shift key using GetAsyncKeyState
 Originally Posted by Davidca
If you subclass the edit control you'll get WM_Keydown/WM_Keyup messages. I confirmed with Spy++ that Notepad's edit control does recieve these messages for Shift.
OK, I'll try subclassing the edit control (which is just a Textbox) and see if I can get a grip on this. I'll post back later when I get an answer to this approach - Thanks for the suggestion.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Jul 14th, 2012, 02:32 AM
#8
New Member
Re: Shift key using GetAsyncKeyState
can you do that?
vb Code:
for i=0 to -1 If GetAsyncKeyState(VK_LSHIFT) Then 'shift pressed ' else 'shift is not pressed End If next i
;
or create a global variable which controls the shift pressed or not
Code:
dim shiftcontrolx as boolean
put this commands to a timer whose interval is 1;
Code:
If GetAsyncKeyState(VK_LSHIFT) Then
'shift pressed
shiftcontrolx=1 ' or true
'
else
'shift is not pressed
shiftcontrolx=0 ' or false
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|