Page 1 of 1

KeyPushed without API and without screens

Posted: Tue Dec 29, 2009 8:21 pm
by donSHAYA
Hi all

I've tried to find out how to get the KeyState without have OpenScreen or OpenWindowedScreen on or use API. The result came to this:

Code: Select all

Procedure ExamineKeyPush()
Enumeration <#HighestGadget>
#K_Back
#K_Tab
#K_Clear
#K_Return
#K_Menu
#K_Pause
#K_Print
#K_Capital
#K_Escape
#K_Space
#K_Prior
#K_Next
#K_End
#K_Home
#K_Left
#K_Up
#K_Right
#K_Down
#K_Select
#K_Execute
#K_Snapshot
#K_Insert
#K_Delete
#K_Help
#K_0
#K_1
#K_2
#K_3
#K_4
#K_5
#K_6
#K_7
#K_8
#K_9
#K_A
#K_B
#K_C
#K_D
#K_E
#K_F
#K_G
#K_H
#K_I
#K_J
#K_K
#K_L
#K_M
#K_N
#K_O
#K_P
#K_Q
#K_R
#K_S
#K_T
#K_U
#K_V
#K_W
#K_X
#K_Y
#K_Z
#K_LeftWindows
#K_RightWindows
#K_Apps
#K_Pad0
#K_Pad1
#K_Pad2
#K_Pad3
#K_Pad4
#K_Pad5
#K_Pad6
#K_Pad7
#K_Pad8
#K_Pad9
#K_Multiply
#K_Add
#K_Separator
#K_Subtract
#K_Decimal
#K_Divide
#K_F1
#K_F2
#K_F3
#K_F4
#K_F5
#K_F6
#K_F7
#K_F8
#K_F9
#K_F10
#K_F11
#K_F12
#K_F13
#K_F14
#K_F15
#K_F16
#K_F17
#K_F18
#K_F19
#K_F20
#K_F21
#K_F22
#K_F23
#K_F24
#K_Numlock
#K_Scroll
EndEnumeration
EndProcedure

Procedure KeyPush(Window, Key, WindowEvent)

UseGadgetList(WindowID(Window))
Select Key
Case #K_Back
If Not IsGadget(#K_Back)
ButtonGadget(#K_Back, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Back, #K_Back)
HideGadget(#K_Back, 1) : EndIf
Case #K_Tab
If Not IsGadget(#K_Tab)
ButtonGadget(#K_Tab, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Tab, #K_Tab)
HideGadget(#K_Tab, 1) : EndIf
Case #K_Clear
If Not IsGadget(#K_Clear)
ButtonGadget(#K_Clear, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Clear, #K_Clear)
HideGadget(#K_Clear, 1) : EndIf
Case #K_Return
If Not IsGadget(#K_Return)
ButtonGadget(#K_Return, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Return, #K_Return)
HideGadget(#K_Return, 1) : EndIf
Case #K_Menu
If Not IsGadget(#K_Menu)
ButtonGadget(#K_Menu, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Menu, #K_Menu)
HideGadget(#K_Menu, 1) : EndIf
Case #K_Pause
If Not IsGadget(#K_Pause)
ButtonGadget(#K_Pause, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pause, #K_Pause)
HideGadget(#K_Pause, 1) : EndIf
Case #K_Print
If Not IsGadget(#K_Print)
ButtonGadget(#K_Print, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Print, #K_Print)
HideGadget(#K_Print, 1) : EndIf
Case #K_Capital
If Not IsGadget(#K_Capital)
ButtonGadget(#K_Capital, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Capital, #K_Capital)
HideGadget(#K_Capital, 1) : EndIf
Case #K_Escape
If Not IsGadget(#K_Escape)
ButtonGadget(#K_Escape, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Escape, #K_Escape)
HideGadget(#K_Escape, 1) : EndIf
Case #K_Space
If Not IsGadget(#K_Space)
ButtonGadget(#K_Space, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Space, #K_Space)
HideGadget(#K_Space, 1) : EndIf
Case #K_Prior
If Not IsGadget(#K_Prior)
ButtonGadget(#K_Prior, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Prior, #K_Prior)
HideGadget(#K_Prior, 1) : EndIf
Case #K_Next
If Not IsGadget(#K_Next)
ButtonGadget(#K_Next, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Next, #K_Next)
HideGadget(#K_Next, 1) : EndIf
Case #K_End
If Not IsGadget(#K_End)
ButtonGadget(#K_End, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_End, #K_End)
HideGadget(#K_End, 1) : EndIf
Case #K_Home
If Not IsGadget(#K_Home)
ButtonGadget(#K_Home, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Home, #K_Home)
HideGadget(#K_Home, 1) : EndIf
Case #K_Left
If Not IsGadget(#K_Left)
ButtonGadget(#K_Left, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Left, #K_Left)
HideGadget(#K_Left, 1) : EndIf
Case #K_Up
If Not IsGadget(#K_Up)
ButtonGadget(#K_Up, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Up, #K_Up)
HideGadget(#K_Up, 1) : EndIf
Case #K_Right
If Not IsGadget(#K_Right)
ButtonGadget(#K_Right, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Right, #K_Right)
HideGadget(#K_Right, 1) : EndIf
Case #K_Down
If Not IsGadget(#K_Down)
ButtonGadget(#K_Down, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Down, #K_Down)
HideGadget(#K_Down, 1) : EndIf
Case #K_Select
If Not IsGadget(#K_Select)
ButtonGadget(#K_Select, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Select, #K_Select)
HideGadget(#K_Select, 1) : EndIf
Case #K_Execute
If Not IsGadget(#K_Execute)
ButtonGadget(#K_Execute, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Execute, #K_Execute)
HideGadget(#K_Execute, 1) : EndIf
Case #K_Snapshot
If Not IsGadget(#K_Snapshot)
ButtonGadget(#K_Snapshot, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Snapshot, #K_Snapshot)
HideGadget(#K_Snapshot, 1) : EndIf
Case #K_Insert
If Not IsGadget(#K_Insert)
ButtonGadget(#K_Insert, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Insert, #K_Insert)
HideGadget(#K_Insert, 1) : EndIf
Case #K_Delete
If Not IsGadget(#K_Delete)
ButtonGadget(#K_Delete, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Delete, #K_Delete)
HideGadget(#K_Delete, 1) : EndIf
Case #K_Help
If Not IsGadget(#K_Help)
ButtonGadget(#K_Help, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Help, #K_Help)
HideGadget(#K_Help, 1) : EndIf
Case #K_0
If Not IsGadget(#K_0)
ButtonGadget(#K_0, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_0, #K_0)
HideGadget(#K_0, 1) : EndIf
Case #K_1
If Not IsGadget(#K_1)
ButtonGadget(#K_1, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_1, #K_1)
HideGadget(#K_1, 1) : EndIf
Case #K_2
If Not IsGadget(#K_2)
ButtonGadget(#K_2, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_2, #K_2)
HideGadget(#K_2, 1) : EndIf
Case #K_3
If Not IsGadget(#K_3)
ButtonGadget(#K_3, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_3, #K_3)
HideGadget(#K_3, 1) : EndIf
Case #K_4
If Not IsGadget(#K_4)
ButtonGadget(#K_4, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_4, #K_4)
HideGadget(#K_4, 1) : EndIf
Case #K_5
If Not IsGadget(#K_5)
ButtonGadget(#K_5, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_5, #K_5)
HideGadget(#K_5, 1) : EndIf
Case #K_6
If Not IsGadget(#K_6)
ButtonGadget(#K_6, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_6, #K_6)
HideGadget(#K_6, 1) : EndIf
Case #K_7
If Not IsGadget(#K_7)
ButtonGadget(#K_7, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_7, #K_7)
HideGadget(#K_7, 1) : EndIf
Case #K_8
If Not IsGadget(#K_8)
ButtonGadget(#K_8, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_8, #K_8)
HideGadget(#K_8, 1) : EndIf
Case #K_9
If Not IsGadget(#K_9)
ButtonGadget(#K_9, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_9, #K_9)
HideGadget(#K_9, 1) : EndIf
Case #K_A
If Not IsGadget(#K_A)
ButtonGadget(#K_A, 0, 0, 100, 100, "")
AddKeyboardShortcut(Window, #PB_Shortcut_A, #K_A)
HideGadget(#K_A, 1) : EndIf
Case #K_B
If Not IsGadget(#K_B)
ButtonGadget(#K_B, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_B, #K_B)
HideGadget(#K_B, 1) : EndIf
Case #K_C
If Not IsGadget(#K_C)
ButtonGadget(#K_C, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_C, #K_C)
HideGadget(#K_C, 1) : EndIf
Case #K_D
If Not IsGadget(#K_D)
ButtonGadget(#K_D, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_D, #K_D)
HideGadget(#K_D, 1) : EndIf
Case #K_E
If Not IsGadget(#K_E)
ButtonGadget(#K_E, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_E, #K_E)
HideGadget(#K_E, 1) : EndIf
Case #K_F
If Not IsGadget(#K_F)
ButtonGadget(#K_F, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F, #K_F)
HideGadget(#K_F, 1) : EndIf
Case #K_G
If Not IsGadget(#K_G)
ButtonGadget(#K_G, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_G, #K_G)
HideGadget(#K_G, 1) : EndIf
Case #K_H
If Not IsGadget(#K_H)
ButtonGadget(#K_H, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_H, #K_H)
HideGadget(#K_H, 1) : EndIf
Case #K_I
If Not IsGadget(#K_I)
ButtonGadget(#K_I, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_I, #K_I)
HideGadget(#K_I, 1) : EndIf
Case #K_J
If Not IsGadget(#K_J)
ButtonGadget(#K_J, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_J, #K_J)
HideGadget(#K_J, 1) : EndIf
Case #K_K
If Not IsGadget(#K_K)
ButtonGadget(#K_K, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_K, #K_K)
HideGadget(#K_K, 1) : EndIf
Case #K_L
If Not IsGadget(#K_L)
ButtonGadget(#K_L, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_L, #K_L)
HideGadget(#K_L, 1) : EndIf
Case #K_M
If Not IsGadget(#K_M)
ButtonGadget(#K_M, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_M, #K_M)
HideGadget(#K_M, 1) : EndIf
Case #K_N
If Not IsGadget(#K_N)
ButtonGadget(#K_N, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_N, #K_N)
HideGadget(#K_N, 1) : EndIf
Case #K_O
If Not IsGadget(#K_O)
ButtonGadget(#K_O, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_O, #K_O)
HideGadget(#K_O, 1) : EndIf
Case #K_P
If Not IsGadget(#K_P)
ButtonGadget(#K_P, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_P, #K_P)
HideGadget(#K_P, 1) : EndIf
Case #K_Q
If Not IsGadget(#K_Q)
ButtonGadget(#K_Q, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Q, #K_Q)
HideGadget(#K_Q, 1) : EndIf
Case #K_R
If Not IsGadget(#K_R)
ButtonGadget(#K_R, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_R, #K_R)
HideGadget(#K_R, 1) : EndIf
Case #K_S
If Not IsGadget(#K_S)
ButtonGadget(#K_S, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_S, #K_S)
HideGadget(#K_S, 1) : EndIf
Case #K_T
If Not IsGadget(#K_T)
ButtonGadget(#K_T, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_T, #K_T)
HideGadget(#K_T, 1) : EndIf
Case #K_U
If Not IsGadget(#K_U)
ButtonGadget(#K_U, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_U, #K_U)
HideGadget(#K_U, 1) : EndIf
Case #K_V
If Not IsGadget(#K_V)
ButtonGadget(#K_V, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_V, #K_V)
HideGadget(#K_V, 1) : EndIf
Case #K_W
If Not IsGadget(#K_W)
ButtonGadget(#K_W, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_W, #K_W)
HideGadget(#K_W, 1) : EndIf
Case #K_X
If Not IsGadget(#K_X)
ButtonGadget(#K_X, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_X, #K_X)
HideGadget(#K_X, 1) : EndIf
Case #K_Y
If Not IsGadget(#K_Y)
ButtonGadget(#K_Y, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Y, #K_Y)
HideGadget(#K_Y, 1) : EndIf
Case #K_Z
If Not IsGadget(#K_Z)
ButtonGadget(#K_Z, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Z, #K_Z)
HideGadget(#K_Z, 1) : EndIf
Case #K_LeftWindows
If Not IsGadget(#K_LeftWindows)
ButtonGadget(#K_LeftWindows, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_LeftWindows, #K_LeftWindows)
HideGadget(#K_LeftWindows, 1) : EndIf
Case #K_RightWindows
If Not IsGadget(#K_RightWindows)
ButtonGadget(#K_RightWindows, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_RightWindows, #K_RightWindows)
HideGadget(#K_RightWindows, 1) : EndIf
Case #K_Apps
If Not IsGadget(#K_Apps)
ButtonGadget(#K_Apps, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Apps, #K_Apps)
HideGadget(#K_Apps, 1) : EndIf
Case #K_Pad0
If Not IsGadget(#K_Pad0)
ButtonGadget(#K_Pad0, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pad0, #K_Pad0)
HideGadget(#K_Pad0, 1) : EndIf
Case #K_Pad1
If Not IsGadget(#K_Pad1)
ButtonGadget(#K_Pad1, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pad1, #K_Pad1)
HideGadget(#K_Pad1, 1) : EndIf
Case #K_Pad2
If Not IsGadget(#K_Pad2)
ButtonGadget(#K_Pad2, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pad2, #K_Pad2)
HideGadget(#K_Pad2, 1) : EndIf
Case #K_Pad3
If Not IsGadget(#K_Pad3)
ButtonGadget(#K_Pad3, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pad3, #K_Pad3)
HideGadget(#K_Pad3, 1) : EndIf
Case #K_Pad4
If Not IsGadget(#K_Pad4)
ButtonGadget(#K_Pad4, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pad4, #K_Pad4)
HideGadget(#K_Pad4, 1) : EndIf
Case #K_Pad5
If Not IsGadget(#K_Pad5)
ButtonGadget(#K_Pad5, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pad5, #K_Pad5)
HideGadget(#K_Pad5, 1) : EndIf
Case #K_Pad6
If Not IsGadget(#K_Pad6)
ButtonGadget(#K_Pad6, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pad6, #K_Pad6)
HideGadget(#K_Pad6, 1) : EndIf
Case #K_Pad7
If Not IsGadget(#K_Pad7)
ButtonGadget(#K_Pad7, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pad7, #K_Pad7)
HideGadget(#K_Pad7, 1) : EndIf
Case #K_Pad8
If Not IsGadget(#K_Pad8)
ButtonGadget(#K_Pad8, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pad8, #K_Pad8)
HideGadget(#K_Pad8, 1) : EndIf
Case #K_Pad9
If Not IsGadget(#K_Pad9)
ButtonGadget(#K_Pad9, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Pad9, #K_Pad9)
HideGadget(#K_Pad9, 1) : EndIf
Case #K_Multiply
If Not IsGadget(#K_Multiply)
ButtonGadget(#K_Multiply, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Multiply, #K_Multiply)
HideGadget(#K_Multiply, 1) : EndIf
Case #K_Add
If Not IsGadget(#K_Add)
ButtonGadget(#K_Add, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Add, #K_Add)
HideGadget(#K_Add, 1) : EndIf
Case #K_Separator
If Not IsGadget(#K_Separator)
ButtonGadget(#K_Separator, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Separator, #K_Separator)
HideGadget(#K_Separator, 1) : EndIf
Case #K_Subtract
If Not IsGadget(#K_Subtract)
ButtonGadget(#K_Subtract, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Subtract, #K_Subtract)
HideGadget(#K_Subtract, 1) : EndIf
Case #K_Decimal
If Not IsGadget(#K_Decimal)
ButtonGadget(#K_Decimal, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Decimal, #K_Decimal)
HideGadget(#K_Decimal, 1) : EndIf
Case #K_Divide
If Not IsGadget(#K_Divide)
ButtonGadget(#K_Divide, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Divide, #K_Divide)
HideGadget(#K_Divide, 1) : EndIf
Case #K_F1
If Not IsGadget(#K_F1)
ButtonGadget(#K_F1, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F1, #K_F1)
HideGadget(#K_F1, 1) : EndIf
Case #K_F2
If Not IsGadget(#K_F2)
ButtonGadget(#K_F2, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F2, #K_F2)
HideGadget(#K_F2, 1) : EndIf
Case #K_F3
If Not IsGadget(#K_F3)
ButtonGadget(#K_F3, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F3, #K_F3)
HideGadget(#K_F3, 1) : EndIf
Case #K_F4
If Not IsGadget(#K_F4)
ButtonGadget(#K_F4, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F4, #K_F4)
HideGadget(#K_F4, 1) : EndIf
Case #K_F5
If Not IsGadget(#K_F5)
ButtonGadget(#K_F5, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F5, #K_F5)
HideGadget(#K_F5, 1) : EndIf
Case #K_F6
If Not IsGadget(#K_F6)
ButtonGadget(#K_F6, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F6, #K_F6)
HideGadget(#K_F6, 1) : EndIf
Case #K_F7
If Not IsGadget(#K_F7)
ButtonGadget(#K_F7, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F7, #K_F7)
HideGadget(#K_F7, 1) : EndIf
Case #K_F8
If Not IsGadget(#K_F8)
ButtonGadget(#K_F8, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F8, #K_F8)
HideGadget(#K_F8, 1) : EndIf
Case #K_F9
If Not IsGadget(#K_F9)
ButtonGadget(#K_F9, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F9, #K_F9)
HideGadget(#K_F9, 1) : EndIf
Case #K_F10
If Not IsGadget(#K_F10)
ButtonGadget(#K_F10, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F10, #K_F10)
HideGadget(#K_F10, 1) : EndIf
Case #K_F11
If Not IsGadget(#K_F11)
ButtonGadget(#K_F11, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F11, #K_F11)
HideGadget(#K_F11, 1) : EndIf
Case #K_F12
If Not IsGadget(#K_F12)
ButtonGadget(#K_F12, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F12, #K_F12)
HideGadget(#K_F12, 1) : EndIf
Case #K_F13
If Not IsGadget(#K_F13)
ButtonGadget(#K_F13, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F13, #K_F13)
HideGadget(#K_F13, 1) : EndIf
Case #K_F14
If Not IsGadget(#K_F14)
ButtonGadget(#K_F14, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F14, #K_F14)
HideGadget(#K_F14, 1) : EndIf
Case #K_F15
If Not IsGadget(#K_F15)
ButtonGadget(#K_F15, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F15, #K_F15)
HideGadget(#K_F15, 1) : EndIf
Case #K_F16
If Not IsGadget(#K_F16)
ButtonGadget(#K_F16, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F16, #K_F16)
HideGadget(#K_F16, 1) : EndIf
Case #K_F17
If Not IsGadget(#K_F17)
ButtonGadget(#K_F17, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F17, #K_F17)
HideGadget(#K_F17, 1) : EndIf
Case #K_F18
If Not IsGadget(#K_F18)
ButtonGadget(#K_F18, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F18, #K_F18)
HideGadget(#K_F18, 1) : EndIf
Case #K_F19
If Not IsGadget(#K_F19)
ButtonGadget(#K_F19, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F19, #K_F19)
HideGadget(#K_F19, 1) : EndIf
Case #K_F20
If Not IsGadget(#K_F20)
ButtonGadget(#K_F20, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F20, #K_F20)
HideGadget(#K_F20, 1) : EndIf
Case #K_F21
If Not IsGadget(#K_F21)
ButtonGadget(#K_F21, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F21, #K_F21)
HideGadget(#K_F21, 1) : EndIf
Case #K_F22
If Not IsGadget(#K_F22)
ButtonGadget(#K_F22, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F22, #K_F22)
HideGadget(#K_F22, 1) : EndIf
Case #K_F23
If Not IsGadget(#K_F23)
ButtonGadget(#K_F23, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F23, #K_F23)
HideGadget(#K_F23, 1) : EndIf
Case #K_F24
If Not IsGadget(#K_F24)
ButtonGadget(#K_F24, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_F24, #K_F24)
HideGadget(#K_F24, 1) : EndIf
Case #K_Numlock
If Not IsGadget(#K_Numlock)
ButtonGadget(#K_Numlock, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Numlock, #K_Numlock)
HideGadget(#K_Numlock, 1) : EndIf
Case #K_Scroll
If Not IsGadget(#K_Scroll)
ButtonGadget(#K_Scroll, 0, 0, 0, 0, "")
AddKeyboardShortcut(Window, #PB_Shortcut_Scroll, #K_Scroll)
HideGadget(#K_Scroll, 1) : EndIf
EndSelect

If WindowEvent = #PB_Event_Menu Or WindowEvent = #PB_Event_Gadget

Select EventGadget()

Case Key
ProcedureReturn 1

EndSelect

EndIf

EndProcedure
I used the function AddKeyboardShortcut. The way it works, is that I created ButtonGadgets to every Key (Keyboard). Then I hided the Gadgets (so the user can't see them) and add the gadgets to AddKeyboardShortcut. Then if the user pushes the key, he also pushes the button (because of the AddKeyboardShortcut). Then it returns 1 if the key is pushed.

There is two Procedure. The first one [ExamineKey()] has to be called before using the other one [KeyPushed()]. The only thing you have to change in the procedure [ExamineKey()] is the constant #HighestGadget. #HighestGadget is your highest number you've used on your gadgets.

The parameter "Window" is which Window you want the keys to work on.

The parameter "Key" is which Key you want to see is being pushed.

The parameter "WindowEvent" is the WindowEvent() or the WaitWindowEvent()

Please let me know if there is any errors. Let me know if there is a better way to do this, if it is not good to your machine and so on. I can take much criticize and feel free to do so. If it is a good way to find out if the key is being pushed feel free to take the source and use it however you want and change it however you want. But please share your changes with us.

I think it is useful for Mac, Windows, and Linux. But the only bad thing is that you can only find out if the key is being pushed if your window is active and open. It is not that good as GetAsyncKeyState.

It should return exactly like GetAsyncKeyState_() & 1. So it should look like this mathematical:

Code: Select all

KeyPush(0, #K_A, Event) = GetAsyncKeyState_(#VK_A) & 1
Thank you and happy new year.

Re: KeyPushed without API and without screens

Posted: Tue Dec 29, 2009 9:04 pm
by Demivec
donSHAYA wrote:I've tried to find out how to get the KeyState without have OpenScreen or OpenWindowedScreen on or use API. The result came to this:
...
snipped
...
The parameter "Window" is which Window you want the keys to work on.
Just one comment, it seems you didn't accomplish your goal, you still need a window open and a lot of little windows (gadgets) to accomplish this.

Unfortunately I don't have any useful suggestions for a better solution at the moment.

Re: KeyPushed without API and without screens

Posted: Tue Dec 29, 2009 9:16 pm
by donSHAYA
Yeah I know I didn't accomplish much. But I'm still working on it (just thought that other could work on it too). But you can do this without screens (that I accomplished).

But thank you very much for your reply