1. Machile level exception

 
 
constant  FIRST_INDEX=1050, 
          LAST_INDEX=1052 
procedure check(integer self, integer event, sequence params)  
?event 
?params[1] 
?params[2] 
    if params[1]=120 then--f9 
         showWindow(Window1,SW_MINIMIZE) 
    elsif params[1]=121 then--f10 
         showWindow(Window1,SW_NORMAL)   
    end if 
 
-- clear the buffer 
-- poke( FIRST_INDEX, peek( LAST_INDEX ) ) this dosen't work I qet a machine level     execption 
end procedure 
setHandler(Screen,w32HKeyDown,routine_id("check")) 
 

This only works once on all further keyDowns nothing happens.

Don Cole

new topic     » topic index » view message » categorize

2. Re: Machile level exception

doncole2009 said...
 
 
constant  FIRST_INDEX=1050, 
          LAST_INDEX=1052 
procedure check(integer self, integer event, sequence params)  
?event 
?params[1] 
?params[2] 
    if params[1]=120 then--f9 
         showWindow(Window1,SW_MINIMIZE) 
    elsif params[1]=121 then--f10 
         showWindow(Window1,SW_NORMAL)   
    end if 
 
-- clear the buffer 
-- poke( FIRST_INDEX, peek( LAST_INDEX ) ) this dosen't work I qet a machine level     execption 
end procedure 
setHandler(Screen,w32HKeyDown,routine_id("check")) 
 

This only works once on all further keyDowns nothing happens.

Don Cole

Don:
First maybe it would help if you said what you were trying to do ?
What the heck is the FIRST_INDEX, LAST_INDEX suppose to represent ?

new topic     » goto parent     » topic index » view message » categorize

3. Re: Machile level exception

bernie said...
doncole2009 said...
 
 
constant  FIRST_INDEX=1050, 
          LAST_INDEX=1052 
procedure check(integer self, integer event, sequence params)  
?event 
?params[1] 
?params[2] 
    if params[1]=120 then--f9 
         showWindow(Window1,SW_MINIMIZE) 
    elsif params[1]=121 then--f10 
         showWindow(Window1,SW_NORMAL)   
    end if 
 
-- clear the buffer 
-- poke( FIRST_INDEX, peek( LAST_INDEX ) ) this dosen't work I qet a machine level     execption 
end procedure 
setHandler(Screen,w32HKeyDown,routine_id("check")) 
 

This only works once on all further keyDowns nothing happens.

Don Cole

Don:
First maybe it would help if you said what you were trying to do ?
What the heck is the FIRST_INDEX, LAST_INDEX suppose to represent ?

Thank you Bernie,

FIRST_INDEX and LAST_INDEX represent the keyboard buffer as per keys.e

On further review I have found that the machine level execption occures because I am trying to use a dos (.ex) program in a window (.exw) program.

What I am trying to do is this:

Press F9 and SW_HIDE the window. Press F10 and have the window reappear. Somewhere in between the keyboard buffer must be cleared.

poke( FIRST_INDEX, peek( LAST_INDEX ) ) works in dos but not in windows.

So what I don't know how to do is clear the keyboard buffer in windows.

Don Cole

new topic     » goto parent     » topic index » view message » categorize

4. Re: Machile level exception

doncole2009 said...
bernie said...
doncole2009 said...
 
 
constant  FIRST_INDEX=1050, 
          LAST_INDEX=1052 
procedure check(integer self, integer event, sequence params)  
?event 
?params[1] 
?params[2] 
    if params[1]=120 then--f9 
         showWindow(Window1,SW_MINIMIZE) 
    elsif params[1]=121 then--f10 
         showWindow(Window1,SW_NORMAL)   
    end if 
 
-- clear the buffer 
-- poke( FIRST_INDEX, peek( LAST_INDEX ) ) this dosen't work I qet a machine level     execption 
end procedure 
setHandler(Screen,w32HKeyDown,routine_id("check")) 
 

This only works once on all further keyDowns nothing happens.

Don Cole

Don:
First maybe it would help if you said what you were trying to do ?
What the heck is the FIRST_INDEX, LAST_INDEX suppose to represent ?

Thank you Bernie,

FIRST_INDEX and LAST_INDEX represent the keyboard buffer as per keys.e

On further review I have found that the machine level execption occures because I am trying to use a dos (.ex) program in a window (.exw) program.

What I am trying to do is this:

Press F9 and SW_HIDE the window. Press F10 and have the window reappear. Somewhere in between the keyboard buffer must be cleared.

poke( FIRST_INDEX, peek( LAST_INDEX ) ) works in dos but not in windows.

So what I don't know how to do is clear the keyboard buffer in windows.

Don Cole

Don:

Set your handler to watch w32HKeyPress ( WM_CHAR message )

and when you see F9 ( code is #78 ) then hide the window.

when you see F10 ( code is #79 ) then show the window.

Bernie

new topic     » goto parent     » topic index » view message » categorize

5. Re: Machile level exception

bernie said...
doncole2009 said...
bernie said...
doncole2009 said...
 
 
constant  FIRST_INDEX=1050, 
          LAST_INDEX=1052 
procedure check(integer self, integer event, sequence params)  
?event 
?params[1] 
?params[2] 
    if params[1]=120 then--f9 
         showWindow(Window1,SW_MINIMIZE) 
    elsif params[1]=121 then--f10 
         showWindow(Window1,SW_NORMAL)   
    end if 
 
-- clear the buffer 
-- poke( FIRST_INDEX, peek( LAST_INDEX ) ) this dosen't work I qet a machine level     execption 
end procedure 
setHandler(Screen,w32HKeyDown,routine_id("check")) 
 

This only works once on all further keyDowns nothing happens.

Don Cole

Don:
First maybe it would help if you said what you were trying to do ?
What the heck is the FIRST_INDEX, LAST_INDEX suppose to represent ?

Thank you Bernie,

FIRST_INDEX and LAST_INDEX represent the keyboard buffer as per keys.e

On further review I have found that the machine level execption occures because I am trying to use a dos (.ex) program in a window (.exw) program.

What I am trying to do is this:

Press F9 and SW_HIDE the window. Press F10 and have the window reappear. Somewhere in between the keyboard buffer must be cleared.

poke( FIRST_INDEX, peek( LAST_INDEX ) ) works in dos but not in windows.

So what I don't know how to do is clear the keyboard buffer in windows.

Don Cole

Don:

Set your handler to watch w32HKeyPress ( WM_CHAR message )

and when you see F9 ( code is #78 ) then hide the window.

when you see F10 ( code is #79 ) then show the window.

Bernie

Hello Bernie,

Set your handler to watch w32HKeyPress ( WM_CHAR message )

How do I do that?

I think you mean w32HKeyDown because F9 AND F10 are unpritable.

Don Cole

new topic     » goto parent     » topic index » view message » categorize

6. Re: Machile level exception

Don:
I don't use the win32lib as I see things are different than the way
I do things.
It looks like you might have to use returnValue() to reset at
the end of your procedure.

I don't know, you will have to get whoever is maintaining the win32lib
to help you.
Bernie

new topic     » goto parent     » topic index » view message » categorize

7. Re: Machile level exception

bernie said...

Don:
I don't use the win32lib as I see things are different than the way
I do things.
It looks like you might have to use returnValue() to reset at
the end of your procedure.

I don't know, you will have to get whoever is maintaining the win32lib
to help you.
Bernie

Thanks Bernie for trying to help.

I found this works:

procedure check(integer self, integer event, sequence params)    
     if params[1]=116 then--f5 
        showWindow(Window1,SW_HIDE) 
     elsif params[1]=117 then--f6 
        showWindow(Window1,SW_SHOWMAXIMIZED) 
     end if 
end procedure 
setHandler(Screen,w32HKeyDown,routine_id("check")) 
 

With two problems I can live with.

1.) I have to hit F5 twice before F6 works.

I think this is because the keyboard buffer must be cleared. I don't know how to do that with win32lib.

2.)When F6 works the window is minimized in the taskbar not maximixed.

At least it's working some what.

Thanks again Don Cole

new topic     » goto parent     » topic index » view message » categorize

8. Re: Machile level exception

You cannot clear the keyboard buffer, because there may be none. If there is one, Windows certainly has total control over it, and won't let you tamper it.

Your application gets a message whenever it has focus and a keyboard event occurs. If you wish to buffer that yourself, you can, of course. If what you need is simply to record whether a window is visible or not, so as to toggle its state, then simply query the visibility of the window using isVisible(), so that you don't even need to remember anything.

CChris

new topic     » goto parent     » topic index » view message » categorize

9. Re: Machile level exception

I just tried this:

include win32lib.ew 
 
constant Window1=create(Window,"test",0,100,100,50,50,0), 
         w=create(Window,"aaa",0,10,10,10,10,0) 
 
procedure check(integer self, integer event, sequence params) 
     if params[1]=116 then--f5  
        showWindow(Window1,SW_HIDE)  
     elsif params[1]=117 then--f6  
        showWindow(Window1,SW_SHOWMAXIMIZED)  
     end if  
end procedure  
setHandler(Screen,w32HKeyDown,routine_id("check")) 
openWindow(w,0) 
 
WinMain(Window1,Normal) 

Program behaves as expected. If you remove or hide w, then, when you hit F5, your app has no visible window, so cannot have focus, so win32lib never knows about F6. Screen refers to all windows of current application, not the whole screen like single task OSes might see it. Hooking int 09 like TSRs used to do just doesn't work. The name is quite misleading, but changing it would break between 95 and 99% of existing code base.

If you want to have a single window which you can hide and show from any application, I think the simplest route is to wrap RegisterHotKey() (see http://msdn.microsoft.com/en-us/library/ms646309.aspx ) and process the WM_HOTKEY message using a raw message handler.

Note that there is a registerHotKey() in win32lib, but it does something which is only mildly related. Another name we are stuck with.

CChris Btw I don't have the quirks you mention on XP Pro. Are you using Win98? There might be bugs in that OS.

new topic     » goto parent     » topic index » view message » categorize

10. Re: Machile level exception

I've a program that uses keyboard hooks to do what you want, I'll get the source today at the evening a provide it to you.

Best regards, Guillermo Bonvehi

new topic     » goto parent     » topic index » view message » categorize

11. Re: Machile level exception

gbonvehi said...

I've a program that uses keyboard hooks to do what you want, I'll get the source today at the evening a provide it to you.

Best regards, Guillermo Bonvehi

Guillermo,

I would like to see this.

CCris,

This is very interesting.

Don Cole

new topic     » goto parent     » topic index » view message » categorize

12. Re: Machile level exception

Hi Don,
I'm at work again and forgot to upload the source yesterday, I'll hope not to forget tonight.
Meanwhile, did you tried setting a returnValue() to the keydown handler?
You may find this interesting (quoted from Win32Lib documentation):

Setting returnValue at any stage causes processing to stop at the step that the value was set in, and return that value to Windows. Example:

          -- prevent Button1 from seeing any space bar keys 
          procedure Button1_KeyDown( integer self, integer event, sequence parms) 
              integer keycode 
              integer shift 
              keycode = parms[1] 
              shift = parms[2] 
              if keycode = VK_SPACE then 
                  -- set return value 
                  returnValue( w32True ) 
              end if 
          end procedure 
          setHandler( Button1, w32HKeyDown, routine_id("Button1_KeyDown")) 

By the way, the number for the keys are defined in w32Keys.e, VK_F5, VK_F6

Regards,
Guillermo

new topic     » goto parent     » topic index » view message » categorize

13. Re: Machile level exception

Ok, here's the code, you may need to tweak it. The w32allot method is win32lib specific but it's easy to emulate if you need.

 
global constant fUser32 = open_dll("user32.dll"), 
        xSetWindowsHookEx = define_c_func(fUser32,"SetWindowsHookExA",{C_INT,C_POINTER,C_POINTER,C_POINTER},C_POINTER), 
        xUnhookWindowsHookEx = define_c_proc(fUser32,"UnhookWindowsHookEx",{C_POINTER}), 
        xCallNextHookEx = define_c_func(fUser32,"CallNextHookEx",{C_POINTER,C_INT,C_POINTER,C_POINTER},C_POINTER), 
        WH_KEYBOARD_LL = 13 
 
constant 
    kbhook_vkCode= w32allot( DWord ), 
    kbhook_scanCode= w32allot( DWord ), 
    kbhook_flags= w32allot( DWord ), 
    kbhook_time= w32allot( DWord ), 
    kbhook_dwExtraInfo= w32allot( DWord ), 
    SIZEOF_KBDLLHOOKSTRUCT       = w32allotted_size() 
 
atom HookKeyboard 
 
function CallBackHook( integer Code, atom wParam, atom lParam ) 
atom vkCode 
integer currvent 
  if Code=0 then 
        if wParam = WM_KEYUP or wParam = WM_SYSKEYUP then 
                vkCode = w32fetch(lParam, kbhook_vkCode) 
                if vkCode = VK_F5 then 
                        -- something 
                        return 1 
                elsif vkCode = VK_F6 then 
                        -- something 
                        return 1 
                end if 
        end if 
  end if 
  return c_func(xCallNextHookEx,{HookKeyboard, Code, wParam, lParam}) 
end function 
 
-- Call this to setup the hook 
        HookKeyboard = c_func(xSetWindowsHookEx, {WH_KEYBOARD_LL, call_back(routine_id("CallBackHook")), instance(), 0 }) 
 
-- Call this to stop the hook 
        c_proc(xUnhookWindowsHookEx,{HookKeyboard}) 
 


I hope this works for you, I copied just the relevant parts, but I think I didn't skip anything you'll need.

Regards,
Guillermo

new topic     » goto parent     » topic index » view message » categorize

14. Re: Machile level exception

gbonvehi said...

Hi Don,
I'm at work again and forgot to upload the source yesterday, I'll hope not to forget tonight.
Meanwhile, did you tried setting a returnValue() to the keydown handler?
You may find this interesting (quoted from Win32Lib documentation):

Setting returnValue at any stage causes processing to stop at the step that the value was set in, and return that value to Windows. Example:

          -- prevent Button1 from seeing any space bar keys 
          procedure Button1_KeyDown( integer self, integer event, sequence parms) 
              integer keycode 
              integer shift 
              keycode = parms[1] 
              shift = parms[2] 
              if keycode = VK_SPACE then 
                  -- set return value 
                  returnValue( w32True ) 
              end if 
          end procedure 
          setHandler( Button1, w32HKeyDown, routine_id("Button1_KeyDown")) 

By the way, the number for the keys are defined in w32Keys.e, VK_F5, VK_F6

Regards,
Guillermo

Thank you Guillero,

Meanwhile, did you tried setting a returnValue() to the keydown handler?

So you mean returnValue(Button1)?

I have one prograsm that In needs returnValue(-1) or it won't work right.

I don't why.

I have another program that needs returnValue(-1) or it also works with doEvents(0).

I use doEvents(0) because it uses less typing. smile

What is the difference in

returnValue(-1), returnValue(0) and returnValue(1)?

I recieved you post on hooking and am studying it.

Thank you Don Cole

new topic     » goto parent     » topic index » view message » categorize

15. Re: Machile level exception

When Windows sends a mesage o a window, it may expect a reply, depending on the message.

returnValue() forces such a reply from the user defined handlers, before the default message processing for the window kicks in. For some messages, the only thing that matters is zero vs nonzero. For other messages, it is a different story. You have to search MSDN for the meaning of the return value of a particular message, or use some other docs.

doEvents() is hardly related, since it forces processing pending messages before returning to caller. You'll use this to refresh a window you repaint inside a handler, for instance. The 0 usually passed to it is Screen actually. You could use a control id to check messages pending for this control specifically.

CChris

new topic     » goto parent     » topic index » view message » categorize

16. Re: Machile level exception

CChris said...

When Windows sends a mesage o a window, it may expect a reply, depending on the message.

returnValue() forces such a reply from the user defined handlers, before the default message processing for the window kicks in. For some messages, the only thing that matters is zero vs nonzero. For other messages, it is a different story. You have to search MSDN for the meaning of the return value of a particular message, or use some other docs.

doEvents() is hardly related, since it forces processing pending messages before returning to caller. You'll use this to refresh a window you repaint inside a handler, for instance. The 0 usually passed to it is Screen actually. You could use a control id to check messages pending for this control specifically.

CChris

No way to edit a post... The above is slightly too vague.

doEvents() checks whether there is a message pending. If so, it triggers the processing of this partiular message and returns, regardless of there being more in the queue. If no message is pending, procedure returns without waiting. And I forgot to mention that the task scheduler is called after a message is processed in this way.

CChris

new topic     » goto parent     » topic index » view message » categorize

17. Re: Machile level exception

Thanks CChris,

Don Cole

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu